簡體   English   中英

此 Node 實例的 N-API 版本為 1。此模塊支持 N-API 版本 3。此 Node 實例無法運行此模塊

[英]The N-API version of this Node instance is 1. This module supports N-API version(s) 3. This Node instance cannot run this module

我有一個簡單的 nodejs 應用程序,它使用 bcrypt 作為依賴項。 在我的本地機器上一切正常,但是當我嘗試在 aws ec2 免費層上部署此節點應用程序時,我收到此錯誤。 看起來免費層有一些服務器限制,但 bcrypt 是一個標准庫。 必須有一種方法可以在 aws 免費層上運行一個簡單的節點應用程序

bcrypt@4.0.1 install /home/ubuntu/backend/node_modules/bcrypt
node-pre-gyp install --fallback-to-build

node-pre-gyp WARN Using request for node-pre-gyp https download 
node-pre-gyp ERR! install error 
node-pre-gyp ERR! stack Error: The N-API version of this Node instance is 1. This module supports N-API version(s) 3. This Node instance cannot run this module.
node-pre-gyp ERR! stack     at Object.module.exports.validate_package_json (/home/ubuntu/backend/node_modules/node-pre-gyp/lib/util/napi.js:82:9)
node-pre-gyp ERR! stack     at validate_config (/home/ubuntu/backend/node_modules/node-pre-gyp/lib/util/versioning.js:229:10)
node-pre-gyp ERR! stack     at Object.module.exports.evaluate (/home/ubuntu/backend/node_modules/node-pre-gyp/lib/util/versioning.js:279:5)
node-pre-gyp ERR! stack     at install (/home/ubuntu/backend/node_modules/node-pre-gyp/lib/install.js:241:31)
node-pre-gyp ERR! stack     at Object.self.commands.(anonymous function) [as install] (/home/ubuntu/backend/node_modules/node-pre-gyp/lib/node-pre-gyp.js:52:37)
node-pre-gyp ERR! stack     at run (/home/ubuntu/backend/node_modules/node-pre-gyp/bin/node-pre-gyp:82:30)
node-pre-gyp ERR! stack     at Object.<anonymous> (/home/ubuntu/backend/node_modules/node-pre-gyp/bin/node-pre-gyp:134:1)
node-pre-gyp ERR! stack     at Module._compile (module.js:652:30)
node-pre-gyp ERR! stack     at Object.Module._extensions..js (module.js:663:10)
node-pre-gyp ERR! stack     at Module.load (module.js:565:32)
node-pre-gyp ERR! System Linux 4.15.0-1057-aws
node-pre-gyp ERR! command "/usr/bin/node" "/home/ubuntu/backend/node_modules/.bin/node-pre-gyp" "install" "--fallback-to-build"
node-pre-gyp ERR! cwd /home/ubuntu/backend/node_modules/bcrypt
node-pre-gyp ERR! node -v v8.10.0
node-pre-gyp ERR! node-pre-gyp -v v0.14.0
node-pre-gyp ERR! not ok 
The N-API version of this Node instance is 1. This module supports N-API version(s) 3. This Node instance cannot run this module.
npm WARN optional Skipping failed optional dependency /chokidar/fsevents:
npm WARN notsup Not compatible with your operating system or architecture: fsevents@2.1.2
npm ERR! Linux 4.15.0-1057-aws
npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "i" "bcrypt"
npm ERR! node v8.10.0
npm ERR! npm  v3.5.2
npm ERR! code ELIFECYCLE

npm ERR! bcrypt@4.0.1 install: `node-pre-gyp install --fallback-to-build`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the bcrypt@4.0.1 install script 'node-pre-gyp install --fallback-to-build'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the bcrypt package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-pre-gyp install --fallback-to-build
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs bcrypt
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls bcrypt
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /home/ubuntu/backend/npm-debug.log

如何在 ec2 免費層上安裝 bcrypt?

我遇到了這個問題,我的問題是使用舊版本的節點 (5.X),當需要版本 >= 10 時。

所以解決方案可能就像升級 node/npm 一樣簡單。 您可以使用 nvm (“節點版本管理器”)輕松完成此操作

NVM 安裝

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash
Output

=> Close and reopen your terminal to start using nvm or run the following to use it now:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

正如上面的輸出所說,您應該關閉並重新打開終端,或者運行命令將 nvm 腳本的路徑添加到當前的 shell 會話中。 你可以做任何對你來說更容易的事情。

安裝nvm ,您只需運行以下命令即可安裝和使用特定版本的節點:

nvm install <version>

例如:

$ nvm install v10.16.3     // Thanks @Joe for your help :)                                              
$ node --version                                                               
v10.16.3

升級node版本>10后,可以安裝bcrypt

$ npm install bcrypt

獲取此錯誤消息或類似信息:

$ npm install -g sqlite3
npm WARN prefer global node-gyp@3.8.0 should be installed with -g

> sqlite3@5.0.0 install /root/.nvm/node_modules/sqlite3
> node-pre-gyp install --fallback-to-build

node-pre-gyp WARN Using request for node-pre-gyp https download
node-pre-gyp ERR! install error
node-pre-gyp ERR! stack Error: The N-API version of this Node instance is 1. This module supports N-API version(s) 3. This Node instance cannot run this module.
  1. 下載最新的節點:(我有 ubuntu,所以 url 可能不同)

curl -sL https://deb.nodesource.com/setup_current.x | sudo -E bash -

  1. 安裝它:

sudo apt-get install -y nodejs

再次嘗試安裝 sqlite:

$ npm install -g sqlite3
    
added 120 packages, and audited 120 packages in 6s

2 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM