问题
I want to install some dependencies and in this case installing node-pty. But when I run it they give me this error:
Error: The module '/home/dev/Documents/project/node_web_kit/node_modules/node-pty/build/Release/pty.node' was compiled against a different Node.js version using NODE_MODULE_VERSION 46. This version of Node.js requires NODE_MODULE_VERSION 51. Please try re-compiling or re-installing
any solutions?
回答1:
The simplest way to be sure is just to delete node_modules and re-run npm i
from scratch, that way all modules will definitely be set up for the new Node version.
回答2:
Rebuild the node-pty module using:
npm rebuild node-pty --update-binary
回答3:
If none of the above worked try rebuilding the package manually:
cd node_modules/<your module>
node-pre-gyp rebuild
This worked for me
回答4:
If deleting your node_modules folder and reinstalling doesn't work for you, nor npm rebuild
, and you are using nvm, you might have a different problem. Mine was that my npm config prefix was not set to my current nvm node version. So you might try this:
npm config delete prefix
npm config set prefix $NVM_DIR/versions/node/vX.X.X
Of course, replace vX.X.X with the nvm installed node version you are using.
回答5:
In case anyone stumbles over this using WebStorm:
The terminal window in WebStorm uses system settings for node, but the run configuration could use a different version, so npm install in the terminal could lead to this error. Just change the node version in your run configuration and it should be fine.
来源:https://stackoverflow.com/questions/43158417/recompiling-node-dependencies-using-another-node-version