AWS:EACCES:权限被拒绝,mkdir '/home/react-app/node_modules/node-sass/vendor'

AWS: EACCES: permission denied, mkdir '/home/react-app/node_modules/node-sass/vendor'

我在 aws ec2 实例上有一个 react-app。我在安装 npm 模块时遇到问题。

出现此错误:

EACCES: permission denied, mkdir '/home/react-app/node_modules/node-sass/vendor'

我已经尝试过这个解决方案,但对我没有用。

EACCES: permission denied, mkdir '/node_modules/node-sass/build' while running npm install on ubuntu

更新

sudo npm install --allow-root --unsafe-perm

我尝试了这个并且它有效但是,当我要通过

构建应用程序时
sudo npm run build

这将 运行 这个命令,

node-sass-chokidar --include-path ./src --include-path ./node_modules src/ -o src/ && react-scripts build

这条线得到了stuck/hanged

Creating an optimized production build...

我该怎么办?

这可能是原因, 据报道,npm 运行 build 在内存有限且没有交换 space 的机器上可能会失败,这在云环境中很常见。即使对于小型项目,此命令也会使系统中的 RAM 使用量增加数百兆字节,因此如果可用内存少于 1 GB,您的构建可能会失败并显示以下消息:

The build failed because the process exited too early. This probably means the system ran out of memory or someone called kill -9 on the process.

如果您完全确定您没有终止进程,请考虑向您正在构建的机器添加一些交换 space,或者在本地构建项目。

改编自https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-exits-too-early