node-pre-gyp install --fallback-to-build 错误

0. 问题

git clone下来代码(express框架)之后, 跑代码报错.
发现node版本过高, 提示Node.js需要更高的NODE_MODULE_VERSION.
需要重新使用npm编译或安装node_modules模块.
执行

npm rebuild

报错:

> [email protected] install /root/project/jujubeServer/node_modules/bcrypt
> node-pre-gyp install --fallback-to-build

internal/modules/cjs/loader.js:800
    throw err;
    ^

Error: Cannot find module '../'
Require stack:
- /root/project/jujubeServer/node_modules/.bin/node-pre-gyp
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:797:15)
    at Function.Module._load (internal/modules/cjs/loader.js:690:27)
    at Module.require (internal/modules/cjs/loader.js:852:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object. (/root/project/jujubeServer/node_modules/.bin/node-pre-gyp:15:20)
    at Module._compile (internal/modules/cjs/loader.js:959:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
    at Module.load (internal/modules/cjs/loader.js:815:32)
    at Function.Module._load (internal/modules/cjs/loader.js:727:14)
    at Function.Module.runMain (internal/modules/cjs/loader.js:1047:10) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '/root/project/jujubeServer/node_modules/.bin/node-pre-gyp' ]
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
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.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2019-11-28T08_56_38_752Z-debug.log

1. 解决

node-pre-gyp install --fallback-to-build 错误
安装node-gyp

npm install -g node-gyp

安装bcrypt(不使用sudo, 报错: 无法创建文件夹)

sudo npm install bcrypt

重新编译

npm rebuild

可以跑代码了, 问题解决!

参考:node-pre-gyp install --fallback-to-build 错误

你可能感兴趣的:(node-pre-gyp install --fallback-to-build 错误)