从GitHub下载模块并按照说明进行构建后,我尝试使用以下方法将其拉入现有项目:

> npm install ../faye

这似乎起到了作用:

> npm list
/home/dave/src/server
└─┬ faye@0.7.1
  ├── cookiejar@1.3.0
  ├── hiredis@0.1.13
  └── redis@0.7.1

但是Node.js找不到模块:

> node app.js
node.js:201
        throw e; // process.nextTick error, or 'error' event on first tick
              ^
Error: Cannot find module 'faye'
    at Function._resolveFilename (module.js:334:11)
    at Function._load (module.js:279:25)
    at Module.require (module.js:357:17)
    at require (module.js:368:17)
    at Object.<anonymous> (/home/dave/src/server/app.js:2:12)
    at Module._compile (module.js:432:26)
    at Object..js (module.js:450:10)
    at Module.load (module.js:351:31)
    at Function._load (module.js:310:12)
    at Array.0 (module.js:470:10)

我真的很想了解这里发生了什么,但我有点不知所措,不知道下一步该去哪里。有什么建议吗?


当前回答

npm install --save module_name

例如,如果错误为:

{[错误:找不到模块“/root/.npm/form data”]代码:“module_NOT_FOUND”}

然后可以通过执行命令npm install--save form data来解决此问题。

其他回答

一种罕见但也可能的情况是模块名称中的拼写错误。执行节点时,我错过了文件名中的“s”。\util.js,它应该是node。\utils.js,并且在这个问题的所有答案中没有找到任何解决方案,直到我发现即使我删除了所有内容,也无法运行该文件!

逐步运行以下命令。它解决了我的问题:

npm缓存清理–强制rm package-lock.jsonrm-r节点模块npm i--保存--旧版对等deps

从项目中删除node_module根文件夹(例如:myApp)。转到myApp文件夹,然后从终端键入以下命令

>myApp>npm install

它将安装项目所需的所有依赖模块。

最终对我有用的是确保在webpack配置中包含任何合并深度依赖项作为外部项:

externals: {
    puppeteer: 'require("puppeteer")',
}

并将package.json中的node_modules路径声明为“extraResource”。

"extraResources": [
    "node_modules/puppeteer,
}

也许像我一样,您将express中的“视图引擎”设置为不存在的引擎,或者尝试使用未注册的模板引擎。确保使用:app.engine('引擎名称',引擎)app.set(“查看引擎”,“引擎名称”)