使用electron项目经常会遇到NODE_MODULE_VERSION
的错误,如下:
error:: Error: The module '<project>/node_modules/electron/node_modules/ref/build/Release/binding.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 57. This version of Node.js requires
NODE_MODULE_VERSION 54. Please try re-compiling or re-installing
the module (for instance, using `npm rebuild` or`npm install`).
搜索你会发现基本都是让你这样解决
yarn add electron-rebuild --dev
./node_modules/.bin/electron-rebuild
但是有个细节前提需要注意,那就是你需要electron-rebuild
重新build的模块必须在dependencies
中,不能在devDependencies
中。因为electron-rebuild
只会rebuild dependencies
中依赖,具体可以看这里ref node version error