node.js npm本地安装ENOENT chmod错误

node.js npm local install ENOENT chmod error

我在 node/react 应用程序上尝试 运行 npm install 时遇到错误,我正在接管该应用程序的开发。

我没有尝试全局安装任何包。我在 M1 Macbook Pro 运行ning Big Sur 上。我用 Homebrew 重新安装了 node 和 npm。我还尝试删除 package-lock.json 文件,清理 npm 缓存,并按照其他一些帖子的建议将 .npmignore 文件添加到目录中; none 其中有效。

这是我 运行 npm install

时的输出
MacBook-Pro-2 frontend % npm install
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: [my project name]-dashboard@0.1.0
npm ERR! Found: webpack@5.39.0
npm ERR! node_modules/webpack
npm ERR!   webpack@"5.39.0" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer webpack@"^4.0.0" from optimize-css-assets-webpack-plugin@6.0.0
npm ERR! node_modules/optimize-css-assets-webpack-plugin
npm ERR!   optimize-css-assets-webpack-plugin@"6.0.0" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
npm ERR! See /Users/<name>/.npm/eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/<name>/.npm/_logs/2021-06-15T17_41_19_910Z-debug.log

我尝试 运行 npm install --legacy-peer-deps,这导致了一个稍微不同的错误:

MacBook-Pro-2 frontend % npm install --legacy-peer-deps
npm WARN deprecated @hapi/topo@3.1.6: This version has been deprecated and is no longer supported or maintained
npm WARN deprecated @hapi/pinpoint@1.0.2: Moved to 'npm install @sideway/pinpoint'
npm WARN deprecated har-validator@5.1.5: this library is no longer supported
npm WARN deprecated @hapi/formula@1.2.0: Moved to 'npm install @sideway/formula'
npm WARN deprecated topojson@3.0.2: Use topojson-client, topojson-server or topojson-simplify directly.
npm WARN deprecated @hapi/address@2.1.4: Moved to 'npm install @sideway/address'
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated @hapi/hoek@8.5.1: This version has been deprecated and is no longer supported or maintained
npm WARN deprecated @hapi/joi@16.1.8: Switch to 'npm install joi'
npm ERR! code ENOENT
npm ERR! syscall chmod
npm ERR! path /Users/<name>/Developer/<directory>/frontend/node_modules/topojson/node_modules/topojson-simplify/bin/toposimplify
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, chmod '/Users/<name>/Developer/<directory>/frontend/node_modules/topojson/node_modules/topojson-simplify/bin/toposimplify'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/<name>/.npm/_logs/2021-06-15T17_41_57_785Z-debug.log

我解决了我自己的问题。我认为这是一个常见的错误消息,有很多可能的解决方案;这是我尝试过的两件事,为我解决了这个问题:

  • 确保你安装了 postgresql(如果你的项目包括一个 postgresql 数据库,就像我的一样)。在带有自制软件的 mac 上,只需 运行 brew install postgresql.

  • 我还将我的 Node.js 版本降级到最新的长期支持版本(之前我使用的是开发版本)。在撰写本文时,LTS 版本为 14.7。

进行这些更改后,我能够正确安装并启动我的站点。