“ npm install bcrypt”失败,并显示“错误:找不到模块'nan'”

时间:2019-01-17 22:41:12

标签: node.js npm npm-install nan bcrypt

我试图让我现有的Angular项目在新笔记本电脑上工作,并且使其启动并运行使我发疯。这是我所做的:

git init 
git clone <project>
cd <project directory>
delete package-lock.json
npm install
npm install --global --production windows-build-tools
npm install bcrypt

倒数第二步是确保每个https://github.com/kelektiv/node.bcrypt.js/wiki/Installation-Instructions都安装了bcrypt依赖项(先前已引起我注意)。但是,无论我尝试什么,都会收到本文结尾处列出的错误。

我已经检查了node_modules文件夹,并且'nan'依赖确实存在。即使如此,我还是尝试再次安装它(根据node error cannot find module already installed在本地和全局安装),并且安装正常。 package.json文件中也列出了“ nan”。

我尝试过:
*这:Error: Cannot find module 'nan'
*像这样卸载节点:How to completely remove node.js from Windows 并卸载我可以在计算机上找到的所有python安装程序(包括我认为可能存在冲突的v3安装程序,但这似乎并不是问题所在)。
*除此之外,谷歌是空白。
*休息一下,等待神的灵感也没有用。

这是错误:

node-pre-gyp WARN Using request for node-pre-gyp https download
node-pre-gyp WARN Tried to download(404): https://github.com/kelektiv/node.bcrypt.js/releases/download/v3.0.3/bcrypt_lib-v3.0.3-node-v64-win32-x64-unknown.tar.gz
node-pre-gyp WARN Pre-built binaries not found for bcrypt@3.0.3 and node@10.15.0 (node-v64 ABI, unknown) (falling back to source compile with node-gyp)
internal/modules/cjs/loader.js:583
    throw err;
    ^

Error: Cannot find module 'nan'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
    at Function.Module._load (internal/modules/cjs/loader.js:507:25)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:22:18)
    at [eval]:1:1
    at Script.runInThisContext (vm.js:96:20)
    at Object.runInThisContext (vm.js:303:38)
    at Object.<anonymous> ([eval]-wrapper:6:22)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at evalScript (internal/bootstrap/node.js:587:27)
gyp: Call to 'node -e "require('nan')"' returned exit status 1 while in binding.gyp. while trying to load binding.gyp
gyp ERR! configure error
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onCpExit (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\configure.js:345:16)
gyp ERR! stack     at ChildProcess.emit (events.js:182:13)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:240:12)
gyp ERR! System Windows_NT 10.0.17134
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "configure" "--fallback-to-build" "--module=C:\\project\\node_modules\\bcrypt\\lib\\binding\\bcrypt_lib.node" "--module_name=bcrypt_lib" "--module_path=C:\\project\\node_modules\\bcrypt\\lib\\binding" "--napi_version=3" "--node_abi_napi=napi" "--napi_build_version=0" "--node_napi_label=node-v64" "--python=C:\\Users\\xxxxx\\.windows-build-tools\\python27\\python.exe"

编辑1

nan软件包已安装def。运行npm list nan时,我得到:

aconcagua@0.0.0 C:\project
+-- @angular-devkit/build-angular@0.8.9
| `-- node-sass@4.11.0
|   `-- nan@2.12.1  deduped
+-- @angular/compiler-cli@6.1.10
| `-- chokidar@1.7.0
|   `-- UNMET OPTIONAL DEPENDENCY fsevents@1.2.6
|     `-- nan@2.12.1  deduped
`-- nan@2.12.1

我也尝试了this并添加了环境变量,但是没有运气。

2 个答案:

答案 0 :(得分:0)

尝试将nan手动安装到正确的子目录中,即

cd $(npm root -g)/npm && npm install nan

答案 1 :(得分:0)

我能解决此问题的唯一方法是重置Windows(10)并重新启动。新颖的笔记本电脑不会太痛苦。不过,找出错误并进行修复会更好。