npm ERR!安装Firebase Tools时(错误号-17,EEXIST:文件已存在,符号链接)



我正在我的新Macbook Air M1上为一个新项目安装Firebase Tools,在运行命令sudo npm install -g firebase-tools时遇到以下问题

npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
npm WARN deprecated har-validator@5.1.5: this library is no longer supported
npm ERR! code EEXIST
npm ERR! syscall symlink
npm ERR! path ../lib/node_modules/firebase-tools/lib/bin/firebase.js
npm ERR! dest /usr/local/bin/firebase
npm ERR! errno -17
npm ERR! EEXIST: file already exists, symlink '../lib/node_modules/firebase-tools/lib/bin/firebase.js' -> '/usr/local/bin/firebase'
npm ERR! File exists: /usr/local/bin/firebase
npm ERR! Remove the existing file and try again, or run npm
npm ERR! with --force to overwrite files recklessly.

我在谷歌上搜索了很多,但没有线索。。。

还尝试使用--force安装npm clean cachenpm clean cache --force和npm,如错误消息所建议的:

npm install -g --force firebase-tools

npm WARN using --force I sure hope you know what you are doing.
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
npm WARN deprecated har-validator@5.1.5: this library is no longer supported
npm ERR! code EEXIST
npm ERR! path /usr/local/bin/firebase
npm ERR! Refusing to delete /usr/local/bin/firebase: node_modules/npm/bin/npm-cli.js symlink target is not controlled by npm /usr/local/bin
npm ERR! File exists: /usr/local/bin/firebase
npm ERR! Remove the existing file and try again, or run npm
npm ERR! with --force to overwrite files recklessly.

更新:我终于找到了如何在mac上找到隐藏的文件,并删除了有问题的文件。我现在得到这个错误:

sudo npm install -g firebase-tools
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
npm WARN deprecated har-validator@5.1.5: this library is no longer supported
/usr/local/bin/firebase -> /usr/local/lib/node_modules/firebase-tools/lib/bin/firebase.js
> re2@1.16.0 install /usr/local/lib/node_modules/firebase-tools/node_modules/re2
> install-from-cache --artifact build/Release/re2.node --host-var RE2_DOWNLOAD_MIRROR || npm run rebuild
Trying https://github.com/uhop/node-re2/releases/download/1.16.0/darwin-x64-83.br ...
Writing to build/Release/re2.node ...
Trying https://github.com/uhop/node-re2/releases/download/1.16.0/darwin-x64-83.gz ...
Writing to build/Release/re2.node ...
Building locally ...
> re2@1.16.0 rebuild /usr/local/lib/node_modules/firebase-tools/node_modules/re2
> node-gyp rebuild
gyp WARN EACCES current user ("nobody") does not have permission to access the dev dir "/Users/macshac/Library/Caches/node-gyp/14.17.1"
gyp WARN EACCES attempting to reinstall using temporary dev dir "/usr/local/lib/node_modules/firebase-tools/node_modules/re2/.node-gyp"
gyp WARN install got an error, rolling back install
gyp WARN install got an error, rolling back install
gyp ERR! configure error 
gyp ERR! stack Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/firebase-tools/node_modules/re2/.node-gyp'
gyp ERR! System Darwin 20.5.0
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /usr/local/lib/node_modules/firebase-tools/node_modules/re2
gyp ERR! node -v v14.17.1
gyp ERR! node-gyp -v v5.1.0
gyp ERR! not ok 
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! re2@1.16.0 rebuild: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the re2@1.16.0 rebuild script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
(node:11071) UnhandledPromiseRejectionWarning: 1
(Use `node --trace-warnings ...` to show where the warning was created)
(node:11071) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:11071) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
> protobufjs@6.11.2 postinstall /usr/local/lib/node_modules/firebase-tools/node_modules/protobufjs
> node scripts/postinstall
+ firebase-tools@9.16.0
added 694 packages from 431 contributors in 32.015s

(没有sudo也不起作用(

用sudo运行命令:尝试在前面有"sudo"的情况下再次运行命令,如下所示:sudo npm install-g firebase tools。这将以管理员权限运行该命令,管理员权限应赋予它创建目录所需的权限。

我终于能够通过使用Command + Shift + G搜索隐藏文件路径/usr/local/bin来删除有问题的现有文件(firebase.js(然后我得到了问题更新中显示的第二组错误。在这一点上,我意识到我所在的目录中已经有了一个firebase项目,并将目录更改为新项目,然后再次运行sudo npm install -g firebase-tools,它就工作了。

我仍然有点困惑,但最终我认为是删除了违规文件。虽然我仍然不确定为什么我所在的目录很重要,因为它是一个全局安装。。。

为了最大限度地减少权限错误的可能性,您可以将npm配置为使用不同的目录。在本例中,您将在主目录中创建并使用隐藏目录。

1-备份计算机。

2-在命令行上,在主目录中,为全局安装创建一个目录:

mkdir~/.npm全局

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

npm配置集前缀'~/.npm global'

4-在您喜欢的文本编辑器中,打开或创建一个~/.profile文件,并添加以下行:

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

5-在命令行上,更新系统变量:

源~/.profile

6-要测试您的新配置,请在不使用sudo:的情况下全局安装软件包

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

NPM_CONFIG_PREFIX=~/.NPM全局

我卸载了自制程序,它似乎解决了这个问题。

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall.sh)"

然后运行npm audit fix

最新更新