web-dev-qa-db-fra.com

La version N-API de cette instance Node est 1. Ce module prend en charge la (les) version (s) N-API 3. Cette instance Node ne peut pas exécuter ce module)

J'ai une application nodejs simple qui utilise bcrypt comme dépendance. Tout fonctionne très bien sur ma machine locale, mais lorsque j'essaie de déployer cette application de nœud sur le niveau gratuit aws ec2, j'obtiens cette erreur. Il semble qu'il existe des limitations de serveur dans l'offre gratuite, mais bcrypt est une bibliothèque standard. Il doit y avoir un moyen d'exécuter une application de nœud simple sur le niveau gratuit d'aws

[email protected] 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: [email protected]
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! [email protected] install: `node-pre-gyp install --fallback-to-build`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] 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

Comment puis-je installer bcrypt sur l'offre gratuite ec2?

2
Ajitesh Singh

Je suis tombé sur cela, et mon problème était d'utiliser une ancienne version de node (5.X), lorsqu'une version> = 10 était requise.

La solution peut donc être aussi simple que la mise à niveau de node/npm. Vous pouvez facilement le faire en utilisant nvm , le "Node Version Manager"

Installation de 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

Comme l'indique la sortie ci-dessus, vous devez soit fermer et rouvrir le terminal, soit exécuter les commandes pour ajouter le chemin du script nvm à la session Shell actuelle. Vous pouvez faire tout ce qui est plus facile pour vous.

Après avoir installé nvm, vous pouvez installer et utiliser la version spécifique du nœud en exécutant simplement cette commande:

nvm install node <version>

Par exemple:

$ nvm install node v10.16.3                                                      
$ node --version                                                               
v10.16.3

Après la mise à niveau du nœud vers la version> 10, vous pouvez installer bcrypt

$ npm install bcrypt
1
Adarsh Senghani