【问题标题】:unable to install "weak" when i am installing npm packages in node application?在节点应用程序中安装 npm 包时无法安装“弱”?
【发布时间】:2019-03-06 19:37:09
【问题描述】:

我已经设置了一个 Aws Ec2 实例来托管我的 Node.js 应用程序。在我使用sudo npm i 安装所有软件包时从 git repo 克隆项目后,因此在软件包安装完成之前它会出现这样的错误

gyp ERR! configure error
gyp ERR! stack Error: EACCES: permission denied, mkdir 
'/home/ubuntu/directory-server/node_modules/weak/build'
gyp ERR! System Linux 4.15.0-1021-aws
gyp ERR! command "/usr/bin/node" 
"/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /home/ubuntu/directory-server/node_modules/weak
gyp ERR! node -v v11.10.1
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok

这是我的 package.json

{
"name": "faunder",
"version": "0.0.1",
"description": "Faunder",
"main": "index.js",
"scripts": {
"clean": "rimraf -rf build && mkdir build",
"build": "babel src -d build && npm run build:copy",
"build:copy": "cp src/conf/config.ini build/conf/config.ini && cp -r 
src/static build/ && cp src/api/handlers/logo-orange.png 
build/api/handlers/logo-orange.png",
"build:deploy": "npm run clean && npm run build && pm2 start 
build/index.js",
"start": "nodemon src/index.js --exec babel-node --presets env"
 },
"author": "shayan.ahmed@utf-labs.com",
"license": "ISC",
"dependencies": {
"babel-preset-env": "^1.6.1",
"cookie-parser": "^1.4.3",
"cors": "^2.8.5",
"count-files": "^2.6.2",
"csvjson": "^5.0.0",
"csvtojson": "^2.0.8",
"dynamic-html-pdf": "0.0.4",
"express": "^4.16.2",
"fs-extra": "^7.0.1",
"htmltopdf": "0.0.8",
"image-to-base64": "^2.0.1",
"ini": "^1.3.5",
"json2csv": "^4.1.6",
"jsonwebtoken": "^8.3.0",
"lodash": "^4.17.10",
"md5": "^2.2.1",
"moment": "^2.21.0",
"mongodb": "^3.0.0-rc0",
"mqtt": "^2.14.0",
"multer": "^1.4.1",
"mysql2": "^1.5.1",
"node-async-loop": "^1.2.2",
"node-dir": "^0.1.17",
"node-schedule": "^1.3.0",
"nodemailer": "^4.6.8",
"nodemon": "^1.18.1",
"rimraf": "^2.6.3",
"save-dev": "^2.0.0",
"sequelize": "^4.27.0"
 },
 "devDependencies" : {
  "babel-cli" : "^6.26.0"
 }
}

当我运行这个命令时sudo npm i 所以这个命令完成了包安装,但在这点之间失败了

gyp ERR! configure error
gyp ERR! stack Error: EACCES: permission denied, mkdir 
'/home/ubuntu/directory-server/node_modules/weak/build'
gyp ERR! System Linux 4.15.0-1021-aws
gyp ERR! command "/usr/bin/node" 
"/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /home/ubuntu/directory-server/node_modules/weak
gyp ERR! node -v v11.10.1
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok

然后它继续完成其余包的安装。但是由于此时我运行我的节点应用程序时失败,所以它会抛出这样的错误

 Error: Cannot find module 'weak'
 0|index  |     at Function.Module._resolveFilename 
 (internal/modules/cjs/loader.js:613:15)
 0|index  |     at Function.Module._load 
 (internal/modules/cjs/loader.js:539:25)
 0|index  |     at Module.require (internal/modules/cjs/loader.js:667:17)
 0|index  |     at require (internal/modules/cjs/helpers.js:20:18)
 0|index  |     at new D (/home/ubuntu/directory- 
 server/node_modules/dnode/index.js:28:20)
 0|index  |     at module.exports (/home/ubuntu/directory- 
 server/node_modules/dnode/index.js:8:12)
 0|index  |     at /home/ubuntu/directory- 
 server/node_modules/phantom/phantom.js:174:13
 0|index  |     at Server.handler (/home/ubuntu/directory- 
 server/node_modules/shoe/index.js:22:9)
 0|index  |     at Server.emit (events.js:197:13)
 0|index  |     at App.emit (/home/ubuntu/directory- 
 server/node_modules/sockjs/lib/sockjs.js:182:27)
 0|index  |     at Session.emit_open (/home/ubuntu/directory- 
 server/node_modules/sockjs/lib/transport.js:107:23)
 0|index  |     at processTicksAndRejections 
 (internal/process/next_tick.js:74:9) code: 'MODULE_NOT_FOUND' }

【问题讨论】:

  • 您可以尝试更改您的节点版本。它可能会有所帮助。
  • 但这行错误'gyp ERR!堆栈错误:EACCES:权限被拒绝,mkdir' 似乎是权限错误?你不认为这是权限错误吗?
  • gyp 错误通常很神秘。上次我遇到这样的问题是因为我使用了错误的节点版本,所以也许它可以帮助,但不确定:)
  • 你能告诉我应该使用什么命令来更新 Aws EC2 上 ubuntu 实例上的节点版本吗?
  • 我尝试了您的建议,但没有奏效。 ://

标签: node.js express ubuntu amazon-ec2


【解决方案1】:

问题是由于 EC2 中的文件夹权限造成的。 以下是您可以尝试的可能解决方案

首先为您从 git 克隆的文件夹授予 chmod 777 权限,然后 试试sudo npm install

如果上述问题仍未解决,请将您的 Node 版本更新为8.x

【讨论】:

    猜你喜欢
    • 2016-10-15
    • 1970-01-01
    • 2018-06-14
    • 2018-08-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-12
    相关资源
    最近更新 更多