【问题标题】:Cannot find modules on mongoose on heroku在heroku上找不到mongoose上的模块
【发布时间】:2019-12-12 05:52:42
【问题描述】:

我的 heroku 应用程序出现错误 2019-08-03T10:56:56.753066+00:00 app[web.1]: Error: Cannot find module './models/Marker' . 我已经在上面看到了topic,但它对我不起作用(删除 node_modules 包不起作用/将 node_modules 添加到 .gitignore)

我的 package.json :

{
  "name": "node_passport_login",
  "version": "2.0.0",
  "description": "Node.js authentication with Passport",
  "main": "app.js",
  "scripts": {
    "start": "node app.js",
    "dev": "nodemon app.js"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "bcryptjs": "^2.4.3",
    "connect-flash": "^0.1.1",
    "ejs": "^2.6.1",
    "express": "^4.17.1",
    "express-ejs-layouts": "^2.5.0",
    "express-session": "^1.15.6",
    "mongodb": "^3.3.0-beta2",
    "mongoose": "^5.6.7",
    "overpass-frontend": "^2.4.3",
    "passport": "^0.4.0",
    "passport-local": "^1.0.0",
    "socket.io": "^2.2.0",
    "socketio": "^1.0.0"
  },
  "devDependencies": {
    "nodemon": "^1.19.1"
  },
  "engines": {
    "node": "10.15.0"
  }
}


需要模型的行:

const Marker = require('./models/Marker');

整个错误:

2019-08-04T11:27:42.587474+00:00 heroku[web.1]: Starting process with command node app.js
2019-08-04T11:27:44.635440+00:00 heroku[web.1]: State changed from starting to crashed
2019-08-04T11:27:44.616214+00:00 heroku[web.1]: Process exited with status 1
2019-08-04T11:27:44.560379+00:00 app[web.1]: internal/modules/cjs/loader.js:583
2019-08-04T11:27:44.560407+00:00 app[web.1]: throw err;
2019-08-04T11:27:44.560409+00:00 app[web.1]: ^
2019-08-04T11:27:44.560410+00:00 app[web.1]:
2019-08-04T11:27:44.560412+00:00 app[web.1]: Error: Cannot find module './models/Marker'
2019-08-04T11:27:44.560416+00:00 app[web.1]: at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
2019-08-04T11:27:44.560418+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:507:25)
2019-08-04T11:27:44.560422+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:637:17)
2019-08-04T11:27:44.560424+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:22:18)
2019-08-04T11:27:44.560425+00:00 app[web.1]: at Object.<anonymous> (/app/app.js:7:16)
2019-08-04T11:27:44.560427+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:689:30)
2019-08-04T11:27:44.560428+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
2019-08-04T11:27:44.560430+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:599:32)
2019-08-04T11:27:44.560431+00:00 app[web.1]: at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
2019-08-04T11:27:44.560433+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:530:3)
2019-08-04T11:27:44.560434+00:00 app[web.1]: at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
2019-08-04T11:27:44.560435+00:00 app[web.1]: at startup (internal/bootstrap/node.js:283:19)
2019-08-04T11:27:44.560437+00:00 app[web.1]: at bootstrapNodeJSCore (internal/bootstrap/node.js:743:3)

heroku local webworks.

编辑:./models/Marker 是猫鼬模式的模块导出目录

【问题讨论】:

  • 什么是./models/Marker
  • @NinoFiliu 这是猫鼬模式的模块导出目录
  • “删除 node_modules 包不起作用/将 node_modules 添加到 .gitignore”—如果已跟踪,您应该绝对从存储库中删除 node_modules/。你不能只添加到.gitignore;它必须被删除,例如使用git rm -r --cached node_modules 之类的东西,然后再次提交和部署。
  • @Chris 我做了git rm -r --cached node_modules 但它打印了fatal: pathspec 'node_modules' did not match any files

标签: node.js heroku npm mongoose mongoose-schema


【解决方案1】:

问题是我在 Windows 上,所以它不区分大小写,我的文件是 marker.js 而不是 Marker.js,所以它在本地工作,但在 linux 上,它需要完全相同的名称

【讨论】:

  • Thx,我遇到了同样的错误,看起来 macOS 也不区分大小写
猜你喜欢
  • 2014-01-02
  • 2021-10-05
  • 2012-04-22
  • 2014-04-08
  • 2014-01-30
  • 2017-10-16
  • 2020-02-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多