简体   繁体   English

部署到Heroku时找不到mongoDB模块

[英]Cannot find mongoDB module when deploying to Heroku

When I deploy my node.js server to Heroku it throws the following error: 当我将node.js服务器部署到Heroku时,它将引发以下错误:

2018-12-27T10:10:28.370131+00:00 app[web.1]: Error: Cannot find module './lib/utils' 2018-12-27T10:10:28.370137+00:00 app[web.1]: at Function.Module._resolveFilename (module.js:538:15) 2018-12-27T10:10:28.370139+00:00 app[web.1]: at Function.Module._load (module.js:468:25) 2018-12-27T10:10:28.370141+00:00 app[web.1]: at Module.require (module.js:587:17) 2018-12-27T10:10:28.370142+00:00 app[web.1]: at require (internal/module.js:11:18) 2018-12-27T10:10:28.370145+00:00 app[web.1]: at Object. 2018-12-27T10:10:28.370131 + 00:00 app [web.1]:错误:找不到模块'./lib/utils'2018-12-27T10:10:28.370137 + 00:00 app [web.1 ]:在Function.Module._resolveFilename(module.js:538:15)2018-12-27T10:10:28.370139 + 00:00 app [web.1]:在Function.Module._load(module.js:468: 25)2018-12-27T10:10:28.370141 + 00:00 app [web.1]:在Module.require(module.js:587:17)2018-12-27T10:10:28.370142 + 00:00 app [ web.1]:在要求时(internal / module.js:11:18)2018-12-27T10:10:28.370145 + 00:00 app [web.1]:在对象。 (/app/node_modules/mongodb-core/index.js:5:15) 2018-12-27T10:10:28.370146+00:00 app[web.1]: at Module._compile (module.js:643:30) 2018-12-27T10:10:28.370148+00:00 app[web.1]: at Object.Module._extensions..js (module.js:654:10) 2018-12-27T10:10:28.370149+00:00 app[web.1]: at Module.load (module.js:556:32) 2018-12-27T10:10:28.370151+00:00 app[web.1]: at tryModuleLoad (module.js:499:12) 2018-12-27T10:10:28.370153+00:00 app[web.1]: at Function.Module._load (module.js:491:3) (/app/node_modules/mongodb-core/index.js:5:15)2018-12-27T10:10:28.370146 + 00:00 app [web.1]:在Module._compile(module.js:643:30 )2018-12-27T10:10:28.370148 + 00:00 app [web.1]:at Object.Module._extensions..js(module.js:654:10)2018-12-27T10:10:28.370149 + 00 :00 app [web.1]:在Module.load(module.js:556:32)2018-12-27T10:10:28:370151 + 00:00 app [web.1]:在tryModuleLoad(module.js:499 :12)2018-12-27T10:10:28.370153 + 00:00 app [web.1]:at Function.Module._load(module.js:491:3)

My node.js server is fully working locally, and saving to the database without any problem. 我的node.js服务器在本地完全可以运行,并且可以毫无问题地保存到数据库中。 Running npm install locally with my current package.json does create a utils.js file under /lib in the node modules. 使用我当前的package.json在本地运行npm install在节点模块中的/ lib下创建一个utils.js文件。 heroku local web build just fine. heroku local web构建就可以了。

I have been re-initiating my package.json time and time again with no success. 我一次又一次地重新启动package.json,但没有成功。

Current package.json is as follows: 当前的package.json如下:

{
  "name": "temperature_web_app",
  "version": "1.0.0",
  "main": "server.js",
  "scripts": {
    "start": "node server.js"
  },
  "author": "Simon Rosengren",
  "license": "ISC",
  "dependencies": {
    "body-parser": "^1.18.3",
    "express": "^4.16.4",
    "mongodb": "^3.1.10",
    "mqtt": "^2.18.8"
  },
  "engines": {
    "node": "8.9.4"
  }
}

Not ignoring the node_modules folder when pushing to heroku master seem to have been the problem. 推送到heroku master时不忽略node_modules文件夹似乎是问题所在。

Removing the node_modules folder and then pushing to master did the trick. 删除node_modules文件夹,然后推送到master即可达到目的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM