【问题标题】:Heroku Deploy Error: Cannot get Node App running after Deploy : Cannot find module '/app/web.js'Heroku 部署错误:部署后无法运行节点应用程序:找不到模块'/app/web.js'
【发布时间】:2014-04-20 19:11:51
【问题描述】:

我有一个使用 Express 和 MongoDB (mongoose) 的 node.js 应用程序。它在本地运行得很好。我将它部署到 heroku 似乎没有问题,但是当我尝试实际启动应用程序时它崩溃了。 heroku 日志这样说:错误:找不到模块'/app/web.js'

我是新手,所以任何帮助将不胜感激。谢谢!应用程序将帮助我的 1 型糖尿病女儿。

package.json:

    {
  "name": "projectglu",
  "version": "0.0.0",
  "dependencies": {
    "express": "~3.4.3",
    "lodash": "~2.4.1",
    "mongoose": "~3.8.8",
    "connect-mongo": "~0.4.0",
    "passport": "~0.2.0",
    "passport-local": "~0.1.6",
    "ejs": "~0.8.4"
  },
  "devDependencies": {
    "grunt": "~0.4.1",
    "grunt-autoprefixer": "~0.4.0",
    "grunt-bower-install": "~0.7.0",
    "grunt-concurrent": "~0.4.1",
    "grunt-contrib-clean": "~0.5.0",
    "grunt-contrib-coffee": "~0.7.0",
    "grunt-contrib-compass": "~0.6.0",
    "grunt-contrib-concat": "~0.3.0",
    "grunt-contrib-copy": "~0.4.1",
    "grunt-contrib-cssmin": "~0.7.0",
    "grunt-contrib-htmlmin": "~0.1.3",
    "grunt-contrib-imagemin": "~0.5.0",
    "grunt-contrib-jshint": "~0.7.1",
    "grunt-contrib-uglify": "~0.2.0",
    "grunt-contrib-watch": "~0.5.2",
    "grunt-google-cdn": "~0.2.0",
    "grunt-newer": "~0.5.4",
    "grunt-ngmin": "~0.0.2",
    "grunt-rev": "~0.1.0",
    "grunt-svgmin": "~0.2.0",
    "grunt-usemin": "~2.0.0",
    "jshint-stylish": "~0.1.3",
    "load-grunt-tasks": "~0.2.0",
    "time-grunt": "~0.2.1",
    "grunt-express-server": "~0.4.5",
    "grunt-open": "~0.2.0",
    "connect-livereload": "~0.3.0",
    "karma-ng-scenario": "~0.1.0",
    "grunt-karma": "~0.6.2",
    "karma-firefox-launcher": "~0.1.3",
    "karma-script-launcher": "~0.1.0",
    "karma-html2js-preprocessor": "~0.1.0",
    "karma-jasmine": "~0.1.5",
    "karma-chrome-launcher": "~0.1.2",
    "requirejs": "~2.1.10",
    "karma-requirejs": "~0.2.1",
    "karma-coffee-preprocessor": "~0.1.2",
    "karma-phantomjs-launcher": "~0.1.1",
    "karma": "~0.10.9",
    "karma-ng-html2js-preprocessor": "~0.1.0",
    "grunt-mocha-test": "~0.8.1",
    "supertest": "~0.8.2",
    "should": "~2.1.0",
    "grunt-env": "~0.4.1",
    "grunt-node-inspector": "~0.1.3",
    "grunt-nodemon": "~0.2.0",
    "open": "~0.0.4"
  },
  "engines": {
    "node": ">=0.10.0"
  },
  "scripts": {
    "test": "grunt test"
  }
}

【问题讨论】:

  • 不是所需的信息。尝试在您的问题中从项目的根目录发布您的“app.js”文件。或者更好的是,只是您正在调用/加载/需要'/app/web.js'的行

标签: javascript node.js mongodb heroku


【解决方案1】:

更清楚的问题可能是当您从 Heroku 网站示例创建 Procfile 时,您正在剪切和粘贴“web: node web.js”,它基本上告诉 Heroku 哪个文件是您的入口点。你可能有一个不同的入口点,比如说.. server.js,所以用“web: node server.js”换掉“web: node web.js”来解决你的问题。

【讨论】:

    【解决方案2】:

    有多种问题可能导致此问题。

    请检查您是否添加了“Procfile”。使用 Procfile(应用程序根目录中的文本文件)明确声明应执行什么命令来启动 web dyno。在这种情况下,您只需要使用 node 执行 Node 脚本即可。

    这是一个 Procfile 示例:

    web: node web.js

    另一个罪魁祸首可能是配置错误的环境变量NODE_ENV。就个人而言,命令 Heroku 设置 NODE_ENV=production 帮助我解决了我遇到的 Cannot find module 错误。当您这样做时,将myapp 替换为您的 Heroku 应用名称。

    heroku labs:enable user-env-compile -a myapp heroku config:set NODE_ENV=production

    如果这无法解决您的问题,请将 devDependencies 中声明的软件包移至 dependencies,以缓解 NODE_ENV 问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-10-21
      • 1970-01-01
      • 2016-12-25
      • 2021-08-17
      • 2018-11-07
      • 1970-01-01
      • 2021-01-06
      • 1970-01-01
      相关资源
      最近更新 更多