node.js - 错误 : Cannot find module 'nan'

标签 node.js npm node-gyp node.js-addon node.js-nan

我正在开发 native Node.js 插件并关注 nan docs

我将 nan 包含到 binding.gyp 中,例如: "include_dirs" : [ "<!(node -e \"require('nan')\")" ]

nan 也在 npm 依赖项中。

但是当我在另一个 Node 模块中安装包时,node-gyp 失败并出现错误

> nnb@1.0.2 install /Users/Shopgate/sandbox/stress/node_modules/nnb
> node-gyp rebuild

module.js:338
    throw err;
          ^
Error: Cannot find module 'nan'
    at Function.Module._resolveFilename (module.js:336:15)
    at Function.Module._load (module.js:278:25)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at [eval]:1:1
    at Object.exports.runInThisContext (vm.js:74:17)
    at Object.<anonymous> ([eval]-wrapper:6:22)
    at Module._compile (module.js:460:26)
    at evalScript (node.js:431:25)
    at startup (node.js:90:7)
gyp: Call to 'node -e "require('nan')"' returned exit status 1. while trying to load binding.gyp

最佳答案

在我的例子中,这是因为 package-lock 文件中缺少一些依赖项。我通过删除它并再次运行 $ npm install 解决了这个问题。

关于node.js - 错误 : Cannot find module 'nan' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34464673/

相关文章:

node.js - 如何从firestore数据库中的云功能更新多个文档?

javascript - 如何在 php 文件/脚本中使用 node.js 代码

c - V8 中 JavaScript 对象的内存布局

node.js - 无法在 Windows 上安装 Atom 包

node.js - 应用程序构建因 native react 异常而失败,评估脚本时出现问题

javascript - 为什么 Grunt 在 node_modules 中安装这么多文件夹?

react-native - 如何告诉 Expo 使用 --legacy-peerdeps 选项安装 npm 依赖项?

node.js - 如何使用 grunt-run 执行 npm 脚本?

node.js - 如何告诉 native Node.js 扩展在哪里可以找到(正确的)libstdc++?

node.js - 如何通过环境变量设置 node-gyp 的 tarball url