此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

查看:1986
本文介绍了此Node实例的N-API版本为1.此模块支持N-API版本3.此Node实例无法运行此模块.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的nodejs应用程序,它使用bcrypt作为依赖项.一切在我的本地计算机上都可以正常工作,但是当我尝试在AWS EC2免费层上部署此节点应用程序时,出现此错误.看起来免费层有一些服务器限制,但是bcrypt是一个标准库.必须有一种方法可以在AWS Free tier上运行简单的节点应用程序

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 node <version>

例如:

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

将节点升级到版本>后, 10,您可以安装bcrypt

$ npm install bcrypt

I have a simple nodejs application which uses bcrypt as a dependency. Everything just works fine on my local machine but when I am trying to deploy this node app on aws ec2 free tier I get this error. Looks like there are some server limitations in free tier but bcrypt is a standard library. There has to be a way to run a simple node app on aws free tier

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

How can I install bcrypt on ec2 free tier?

解决方案

I came across this, and my issue was using an older version of node (5.X), when a version >= 10 was required.

So the solution may be as simple as upgrading node/npm. You can easily do this using nvm, the "Node Version Manager"

NVM Installation

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

As the output above says, you should either close and reopen the terminal or run the commands to add the path to nvm script to the current shell session. You can do whatever is easier for you.

After you've installed nvm, you can install and use the specific version of node by simply running this command:

nvm install node <version>

For example:

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

After upgrading node to version > 10, you can install bcrypt

$ npm install bcrypt

这篇关于此Node实例的N-API版本为1.此模块支持N-API版本3.此Node实例无法运行此模块.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆