即使使用 sudo,Yeoman 也会给出权限错误



我按照本教程安装了Yeoman和Azure的生成器。

所以,当我这样做时:sudo yo azuresfcontainer,它给了我以下错误:

/usr/local/lib/node_modules/yo/node_modules/fast-glob/out/providers/reader-sync.js:45
throw err;
^
Error: EACCES: permission denied, scandir '/usr/lib/ssl/private'
at Object.fs.readdirSync (fs.js:875:3)
at exports.readdir (/usr/local/lib/node_modules/yo/node_modules/@mrmlnc/readdir-enhanced/lib/sync/fs.js:18:20)
at Object.safeCall [as safe] (/usr/local/lib/node_modules/yo/node_modules/@mrmlnc/readdir-enhanced/lib/call.js:24:8)
at DirectoryReader.readNextDirectory (/usr/local/lib/node_modules/yo/node_modules/@mrmlnc/readdir-enhanced/lib/directory-reader.js:78:10)
at Readable.DirectoryReader.stream._read (/usr/local/lib/node_modules/yo/node_modules/@mrmlnc/readdir-enhanced/lib/directory-reader.js:57:18)
at Readable.read (_stream_readable.js:455:10)
at readdirSync (/usr/local/lib/node_modules/yo/node_modules/@mrmlnc/readdir-enhanced/lib/sync/index.js:27:21)
at Function.readdirSyncStat (/usr/local/lib/node_modules/yo/node_modules/@mrmlnc/readdir-enhanced/lib/index.js:34:10)
at ReaderSync.dynamicApi (/usr/local/lib/node_modules/yo/node_modules/fast-glob/out/providers/reader-sync.js:61:24)
at ReaderSync.api (/usr/local/lib/node_modules/yo/node_modules/fast-glob/out/providers/reader-sync.js:53:25)
Emitted 'error' event at:
at DirectoryReader.emit (/usr/local/lib/node_modules/yo/node_modules/@mrmlnc/readdir-enhanced/lib/directory-reader.js:365:14)
at call.safe (/usr/local/lib/node_modules/yo/node_modules/@mrmlnc/readdir-enhanced/lib/directory-reader.js:81:14)
at onceWrapper (/usr/local/lib/node_modules/yo/node_modules/@mrmlnc/readdir-enhanced/lib/call.js:45:17)
at onceWrapper (/usr/local/lib/node_modules/yo/node_modules/@mrmlnc/readdir-enhanced/lib/call.js:45:17)
at exports.readdir (/usr/local/lib/node_modules/yo/node_modules/@mrmlnc/readdir-enhanced/lib/sync/fs.js:22:5)
at Object.safeCall [as safe] (/usr/local/lib/node_modules/yo/node_modules/@mrmlnc/readdir-enhanced/lib/call.js:24:8)
[... lines matching original stack trace ...]
at readdirSync (/usr/local/lib/node_modules/yo/node_modules/@mrmlnc/readdir-enhanced/lib/sync/index.js:27:21)

我哪里做错了?

我不认为你做错了什么,看起来 yeoman 的依赖破坏了 yeoman。 这是自耕人环境依赖关系,此问题已打开: https://github.com/yeoman/environment/issues/97 复制粘贴以下问题:

运行 yo 时,发生以下错误:错误:EACCES: 权限被拒绝,scandir '/usr/sbin/authserver (MacOS/High Sierra(

罪魁祸首在这里:

// Adds support for generator resolving when yeoman-generator has been linked
if (process.argv[1]) {
paths.push(path.join(path.dirname(process.argv[1]), '../..'));
}

在getNpmPaths((中。我的 yo 在/usr/local/bin/yo,这添加了 整个/usr 目录到搜索路径 => globby.sync 里面 resolver.findsGeneratorIn 如果某些目录不是用户,则会抛出 读。

像这样的事情可以解决这个问题:

try {
modules = modules.concat(globby.sync(
['generator-*', '@*/generator-*'],
{cwd: root, onlyFiles: false, absolute: true}
));
} catch(err) {
debug( 'Could not access %s (%s)', root, err); 
}

我能够通过将全局包安装到不同的文件夹来解决此问题。 https://docs.npmjs.com/getting-started/fixing-npm-permissions

若要最大程度地减少权限错误的可能性,可以将 npm 配置为 使用其他目录。在此示例中,它将是隐藏的 主文件夹中的目录。

在开始之前备份计算机。

为全局安装创建一个目录:

mkdir ~/.npm-global 

配置 npm 以使用新的目录路径:

npm config set prefix '~/.npm-global'

打开或创建一个 ~/.profile 文件并添加以下行:

export PATH=~/.npm-global/bin:$PATH

返回命令行,更新系统变量:

source ~/.profile

测试:全局下载包,不使用 sudo。

npm install -g jshint

代替步骤 2-4,您可以使用相应的 ENV 变量(例如,如果您不想修改 ~/.profile(:

NPM_CONFIG_PREFIX=~/.npm-global

相关内容

  • 没有找到相关文章

最新更新