错误:无法找到模块' ./格式'在heroku服务器上部署节点应用程序时

时间:2017-06-19 11:34:59

标签: node.js heroku

我在heroku上创建了免费帐户。我正在尝试在此部署节点应用程序,但这显示以下错误。

2017-06-19T11:25:53.680527+00:00 app[web.1]: > mypu@1.0.0 start /app
2017-06-19T11:25:53.680528+00:00 app[web.1]: > node server.js
2017-06-19T11:25:53.680528+00:00 app[web.1]: 
2017-06-19T11:25:53.862204+00:00 app[web.1]: module.js:471
2017-06-19T11:25:53.862207+00:00 app[web.1]:     throw err;
2017-06-19T11:25:53.862208+00:00 app[web.1]:     ^
2017-06-19T11:25:53.862209+00:00 app[web.1]: 
2017-06-19T11:25:53.862210+00:00 app[web.1]: Error: Cannot find module './formats'
2017-06-19T11:25:53.862211+00:00 app[web.1]:     at Function.Module._resolveFilename (module.js:469:15)
2017-06-19T11:25:53.862212+00:00 app[web.1]:     at Function.Module._load (module.js:417:25)
2017-06-19T11:25:53.862212+00:00 app[web.1]:     at Module.require (module.js:497:17)
2017-06-19T11:25:53.862213+00:00 app[web.1]:     at require (internal/module.js:20:19)
2017-06-19T11:25:53.862229+00:00 app[web.1]:     at Object.<anonymous> (/app/node_modules/qs/lib/stringify.js:4:15)
2017-06-19T11:25:53.862230+00:00 app[web.1]:     at Module._compile (module.js:570:32)
2017-06-19T11:25:53.862231+00:00 app[web.1]:     at Object.Module._extensions..js (module.js:579:10)
2017-06-19T11:25:53.862231+00:00 app[web.1]:     at Module.load (module.js:487:32)
2017-06-19T11:25:53.862232+00:00 app[web.1]:     at tryModuleLoad (module.js:446:12)
2017-06-19T11:25:53.862233+00:00 app[web.1]:     at Function.Module._load (module.js:438:3)
2017-06-19T11:25:53.872899+00:00 app[web.1]: 
2017-06-19T11:25:53.886139+00:00 app[web.1]: npm ERR! Linux 3.13.0-112-generic
2017-06-19T11:25:53.886419+00:00 app[web.1]: npm ERR! argv "/app/.heroku/node/bin/node" "/app/.heroku/node/bin/npm" "start"
2017-06-19T11:25:53.886602+00:00 app[web.1]: npm ERR! node v6.11.0
2017-06-19T11:25:53.886778+00:00 app[web.1]: npm ERR! npm  v3.10.10
2017-06-19T11:25:53.886955+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2017-06-19T11:25:53.887988+00:00 app[web.1]: npm ERR! mypu@1.0.0 start: `node server.js`
2017-06-19T11:25:53.888109+00:00 app[web.1]: npm ERR! Exit status 1
2017-06-19T11:25:53.888249+00:00 app[web.1]: npm ERR! 
2017-06-19T11:25:53.888373+00:00 app[web.1]: npm ERR! Failed at the mypu@1.0.0 start script 'node server.js'.
2017-06-19T11:25:53.888490+00:00 app[web.1]: npm ERR! Make sure you have the latest version of node.js and npm installed.
2017-06-19T11:25:53.888603+00:00 app[web.1]: npm ERR! If you do, this is most likely a problem with the mypu package,
2017-06-19T11:25:53.888719+00:00 app[web.1]: npm ERR! not with npm itself.
2017-06-19T11:25:53.889463+00:00 app[web.1]: npm ERR! Tell the author that this fails on your system:
2017-06-19T11:25:53.889583+00:00 app[web.1]: npm ERR!     node server.js
2017-06-19T11:25:53.889701+00:00 app[web.1]: npm ERR! You can get information on how to open an issue for this project with:
2017-06-19T11:25:53.889807+00:00 app[web.1]: npm ERR!     npm bugs mypu
2017-06-19T11:25:53.890108+00:00 app[web.1]: npm ERR! Or if that isn't available, you can get their info via:
2017-06-19T11:25:53.890263+00:00 app[web.1]: npm ERR!     npm owner ls mypu
2017-06-19T11:25:53.890433+00:00 app[web.1]: npm ERR! There is likely additional logging output above.
2017-06-19T11:25:53.898834+00:00 app[web.1]: 
2017-06-19T11:25:53.899088+00:00 app[web.1]: npm ERR! Please include the following file with any support request:
2017-06-19T11:25:53.899216+00:00 app[web.1]: npm ERR!     /app/npm-debug.log
Disconnected from log stream. There may be events happening that you do not see here! Attempting to reconnect...
2017-06-19T11:25:53.888719+00:00 app[web.1]: npm ERR! not with npm itself.
2017-06-19T11:25:53.889463+00:00 app[web.1]: npm ERR! Tell the author that this fails on your system:
2017-06-19T11:25:53.889583+00:00 app[web.1]: npm ERR!     node server.js
2017-06-19T11:25:53.889701+00:00 app[web.1]: npm ERR! You can get information on how to open an issue for this project with:
2017-06-19T11:25:53.889807+00:00 app[web.1]: npm ERR!     npm bugs mypu
2017-06-19T11:25:53.890108+00:00 app[web.1]: npm ERR! Or if that isn't available, you can get their info via:
2017-06-19T11:25:53.890263+00:00 app[web.1]: npm ERR!     npm owner ls mypu
2017-06-19T11:25:53.890433+00:00 app[web.1]: npm ERR! There is likely additional logging output above.
2017-06-19T11:25:53.898834+00:00 app[web.1]: 
2017-06-19T11:25:53.899088+00:00 app[web.1]: npm ERR! Please include the following file with any support request:
2017-06-19T11:25:53.899216+00:00 app[web.1]: npm ERR!     /app/npm-debug.log
Disconnected from log stream. There may be events happening that you do not see here! Attempting to reconnect...
Disconnected from log stream. There may be events happening that you do not see here! Attempting to reconnect...
2017-06-19T11:25:53.888719+00:00 app[web.1]: npm ERR! not with npm itself.
2017-06-19T11:25:53.889463+00:00 app[web.1]: npm ERR! Tell the author that this fails on your system:
2017-06-19T11:25:53.889583+00:00 app[web.1]: npm ERR!     node server.js
2017-06-19T11:25:53.889701+00:00 app[web.1]: npm ERR! You can get information on how to open an issue for this project with:
2017-06-19T11:25:53.889807+00:00 app[web.1]: npm ERR!     npm bugs mypu
2017-06-19T11:25:53.890108+00:00 app[web.1]: npm ERR! Or if that isn't available, you can get their info via:
2017-06-19T11:25:53.890263+00:00 app[web.1]: npm ERR!     npm owner ls mypu
2017-06-19T11:25:53.890433+00:00 app[web.1]: npm ERR! There is likely additional logging output above.
2017-06-19T11:25:53.898834+00:00 app[web.1]: 
2017-06-19T11:25:53.899088+00:00 app[web.1]: npm ERR! Please include the following file with any support request:
2017-06-19T11:25:53.899216+00:00 app[web.1]: npm ERR!     /app/npm-debug.log
Disconnected from log stream. There may be events happening that you do not see here! Attempting to reconnect...
2017-06-19T11:25:53.888719+00:00 app[web.1]: npm ERR! not with npm itself.
2017-06-19T11:25:53.889463+00:00 app[web.1]: npm ERR! Tell the author that this fails on your system:
2017-06-19T11:25:53.889583+00:00 app[web.1]: npm ERR!     node server.js
2017-06-19T11:25:53.889701+00:00 app[web.1]: npm ERR! You can get information on how to open an issue for this project with:
2017-06-19T11:25:53.889807+00:00 app[web.1]: npm ERR!     npm bugs mypu
2017-06-19T11:25:53.890108+00:00 app[web.1]: npm ERR! Or if that isn't available, you can get their info via:
2017-06-19T11:25:53.890263+00:00 app[web.1]: npm ERR!     npm owner ls mypu
2017-06-19T11:25:53.890433+00:00 app[web.1]: npm ERR! There is likely additional logging output above.
2017-06-19T11:25:53.898834+00:00 app[web.1]: 
2017-06-19T11:25:53.899088+00:00 app[web.1]: npm ERR! Please include the following file with any support request:
2017-06-19T11:25:53.899216+00:00 app[web.1]: npm ERR!     /app/npm-debug.log
Disconnected from log stream. There may be events happening that you do not see here! Attempting to reconnect...
2017-06-19T11:25:53.888719+00:00 app[web.1]: npm ERR! not with npm itself.
2017-06-19T11:25:53.889463+00:00 app[web.1]: npm ERR! Tell the author that this fails on your system:
2017-06-19T11:25:53.889583+00:00 app[web.1]: npm ERR!     node server.js
2017-06-19T11:25:53.889701+00:00 app[web.1]: npm ERR! You can get information on how to open an issue for this project with:
2017-06-19T11:25:53.889807+00:00 app[web.1]: npm ERR!     npm bugs mypu
2017-06-19T11:25:53.890108+00:00 app[web.1]: npm ERR! Or if that isn't available, you can get their info via:
2017-06-19T11:25:53.890263+00:00 app[web.1]: npm ERR!     npm owner ls mypu
2017-06-19T11:25:53.890433+00:00 app[web.1]: npm ERR! There is likely additional logging output above.

相同的应用程序适用于我的本地计算机。这是package.json

{
  "name": "mypu",
  "version": "1.0.0",
  "description": "mypu",
  "main": "index.js",
  "scripts": {
    "start" : "node server.js"
  },
  "repository": {
    "type": "git",
    "url": ""
  },
  "author": "",
  "license": "ISC",
  "bugs": {
    "url": ""
  },
  "homepage": "",
  "dependencies": {
    "body-parser": "^1.15.0",
    "connect-timeout": "^1.8.0",
    "express": "^4.13.4",
    "generic-pool": "^2.4.2",
    "log4js": "^1.1.1",
    "multer": "^1.2.0",
    "mysql": "^2.10.2",
    "requestify": "^0.1.17"
  }
}

可能是什么问题?我错过了什么吗?

3 个答案:

答案 0 :(得分:2)

是的,由于您的案例中缺少模块而发生此错误错误:无法找到模块&#39; ./格式&#39; 。您必须清理现有的 node_modules 目录并运行npm install 新安装所有依赖项。如果您仍然在部署中遇到问题,请通过此链接获取更多详细信息

https://devcenter.heroku.com/articles/deploying-nodejs

https://scotch.io/tutorials/how-to-deploy-a-node-js-app-to-heroku

https://www.youtube.com/watch?v=6Fu39V6T_G0

答案 1 :(得分:1)

就我而言,我的存储库中存在node_modules目录。我从github存储库中排除了它并再次部署。现在它正在运作

答案 2 :(得分:1)

删除node_modules的缓存并重新部署:

git rm -r --cached node_modules

然后git push heroku master

如果您在重新部署时不想要缓存node_module,也可以禁用缓存:

heroku config:set NODEMODULESCACHE=false
git commit -am 'rebuild' --allow-empty
git push heroku master
heroku config:unset NODEMODULESCACHE

这对我有用!