NPM模块参考不适用于Mongoose

时间:2021-07-22 19:36:47

So when trying to deploy a Node.js app to Heroku, I am getting this error with heroku logs -t.

因此,当尝试将Node.js应用程序部署到Heroku时,我使用heroku logs -t收到此错误。

> State changed from crashed to starting Starting process with command
> `node ./bin/www`  Detected 512 MB available memory, 512 MB limit per
> process (WEB_MEMORY)  Recommending WEB_CONCURRENCY=1    Error: Cannot
> find module 'mongodb/lib/read_preference'
>      throw err;  module.js:340
>            ^
>      at Function.Module._resolveFilename (module.js:338:15)
>      at Function.Module._load (module.js:280:25)
>      at Module.require (module.js:364:17)
>      at require (module.js:380:17)
>      at Module._compile (module.js:456:26)
>      at Object.Module._extensions..js (module.js:474:10)
>      at Object.<anonymous> (/app/node_modules/mongoose/lib/utils.js:5:16)
>      at Module.load (module.js:356:32)
>      at Function.Module._load (module.js:312:12)
>      at Module.require (module.js:364:17)

The folder structure of the file looking for the target file is such (inside the node_modules folder):

查找目标文件的文件的文件夹结构是这样的(在node_modules文件夹内):

mongoose/lib/utils.js

and the code looking for the file is such:

并且寻找文件的代码是这样的:

var ReadPref = require('mongodb/lib/read_preference')

and the target file is at:

目标文件位于:

mongoose/node_modules/mongodb/lib/read_preference.js

Now based on Node's searching algorithm (https://nodejs.org/api/modules.html), the file will move up to the node_modules folder and then search for mongodb, find it and enter its folder, finally getting to the read_preference file. However, this obviously isn't working. What can I do to fix this?

现在基于Node的搜索算法(https://nodejs.org/api/modules.html),文件将移动到node_modules文件夹,然后搜索mongodb,找到它并输入其文件夹,最后转到read_preference文件。但是,这显然不起作用。我该怎么做才能解决这个问题?

1 个解决方案

#1


Why you say?

为什么你说?

Heroku caches your modules, so any updates to package.json won't get recognized. So your local copy will be blatantly correct; however, Heroku's won't. In order to overcome this, type:

Heroku缓存您的模块,因此无法识别对package.json的任何更新。因此,您的本地副本将是公然正确的;然而,Heroku不会。为了克服这个问题,输入:

heroku config:set NODE_MODULES_CACHE=false

heroku config:设置NODE_MODULES_CACHE = false

#1


Why you say?

为什么你说?

Heroku caches your modules, so any updates to package.json won't get recognized. So your local copy will be blatantly correct; however, Heroku's won't. In order to overcome this, type:

Heroku缓存您的模块,因此无法识别对package.json的任何更新。因此,您的本地副本将是公然正确的;然而,Heroku不会。为了克服这个问题,输入:

heroku config:set NODE_MODULES_CACHE=false

heroku config:设置NODE_MODULES_CACHE = false