【问题标题】:How can I move past npm errors on Heroku?如何在 Heroku 上跳过 npm 错误?
【发布时间】:2020-01-05 23:08:34
【问题描述】:

我有一个在本地运行的 express 应用,现在是时候在 Heroku 上部署到生产环境了。但是在开始时,在构建之后,我得到了这个错误。

2019-09-03T04:06:50.000000+00:00 app[api]: Build succeeded
2019-09-03T04:06:51.827053+00:00 heroku[web.1]: State changed from crashed to starting
2019-09-03T04:06:56.430361+00:00 heroku[web.1]: Starting process with command `npm start`
2019-09-03T04:06:58.584750+00:00 app[web.1]: 
2019-09-03T04:06:58.584779+00:00 app[web.1]: > paulandbarnabas@1.0.0 start /app
2019-09-03T04:06:58.584781+00:00 app[web.1]: > node app.js
2019-09-03T04:06:58.584783+00:00 app[web.1]: 
2019-09-03T04:06:59.613043+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2019-09-03T04:06:59.613439+00:00 app[web.1]: npm ERR! errno 1
2019-09-03T04:06:59.614920+00:00 app[web.1]: npm ERR! paulandbarnabas@1.0.0 start: `node app.js`
2019-09-03T04:06:59.615108+00:00 app[web.1]: npm ERR! Exit status 1
2019-09-03T04:06:59.615340+00:00 app[web.1]: npm ERR!
2019-09-03T04:06:59.615490+00:00 app[web.1]: npm ERR! Failed at the paulandbarnabas@1.0.0 start script.
2019-09-03T04:06:59.615636+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2019-09-03T04:06:59.622218+00:00 app[web.1]: 
2019-09-03T04:06:59.622356+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2019-09-03T04:06:59.622440+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2019-09-03T04_06_59_617Z-debug.log
2019-09-03T04:06:59.692539+00:00 heroku[web.1]: State changed from crashed to starting
2019-09-03T04:06:59.685997+00:00 heroku[web.1]: State changed from starting to crashed
2019-09-03T04:06:59.661050+00:00 heroku[web.1]: Process exited with status 1
2019-09-03T04:07:05.183158+00:00 heroku[web.1]: Starting process with command `npm start`
2019-09-03T04:07:08.450218+00:00 app[web.1]: 
2019-09-03T04:07:08.450244+00:00 app[web.1]: > paulandbarnabas@1.0.0 start /app
2019-09-03T04:07:08.450247+00:00 app[web.1]: > node app.js
2019-09-03T04:07:08.450248+00:00 app[web.1]: 
2019-09-03T04:07:10.666403+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2019-09-03T04:07:10.669449+00:00 app[web.1]: npm ERR! errno 1
2019-09-03T04:07:10.674407+00:00 app[web.1]: npm ERR! paulandbarnabas@1.0.0 start: `node app.js`
2019-09-03T04:07:10.674672+00:00 app[web.1]: npm ERR! Exit status 1
2019-09-03T04:07:10.675056+00:00 app[web.1]: npm ERR!
2019-09-03T04:07:10.675318+00:00 app[web.1]: npm ERR! Failed at the paulandbarnabas@1.0.0 start script.
2019-09-03T04:07:10.675575+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2019-09-03T04:07:10.684965+00:00 app[web.1]: 
2019-09-03T04:07:10.685272+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2019-09-03T04:07:10.685494+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2019-09-03T04_07_10_677Z-debug.log
2019-09-03T04:07:10.780791+00:00 heroku[web.1]: State changed from starting to crashed
2019-09-03T04:07:10.757752+00:00 heroku[web.1]: Process exited with status 1

当我将 NODE_ENV 环境变量更改为“开发”时,我收到此错误...

2019-09-03T15:13:00.802982+00:00 heroku[web.1]: State changed from crashed to starting
2019-09-03T15:13:08.180817+00:00 heroku[web.1]: Starting process with command `npm start`
2019-09-03T15:13:12.134636+00:00 app[web.1]: 
2019-09-03T15:13:12.134659+00:00 app[web.1]: > paulandbarnabas@1.0.0 start /app
2019-09-03T15:13:12.134662+00:00 app[web.1]: > node app.js
2019-09-03T15:13:12.134664+00:00 app[web.1]: 
2019-09-03T15:13:15.611192+00:00 app[web.1]: module.js:545
2019-09-03T15:13:15.611213+00:00 app[web.1]: throw err;
2019-09-03T15:13:15.611215+00:00 app[web.1]: ^
2019-09-03T15:13:15.611217+00:00 app[web.1]: 
2019-09-03T15:13:15.611223+00:00 app[web.1]: Error: Cannot find module 'dynamic-url-constructor'
2019-09-03T15:13:15.611225+00:00 app[web.1]: at Function.Module._resolveFilename (module.js:543:15)
2019-09-03T15:13:15.611228+00:00 app[web.1]: at Function.Module._load (module.js:470:25)
2019-09-03T15:13:15.611230+00:00 app[web.1]: at Module.require (module.js:593:17)
2019-09-03T15:13:15.611232+00:00 app[web.1]: at require (internal/module.js:11:18)
2019-09-03T15:13:15.611235+00:00 app[web.1]: at Object.<anonymous> (/app/utils/URLConstructor.util.js:7:22)
2019-09-03T15:13:15.611238+00:00 app[web.1]: at Module._compile (module.js:649:30)
2019-09-03T15:13:15.611240+00:00 app[web.1]: at Object.Module._extensions..js (module.js:660:10)
2019-09-03T15:13:15.611242+00:00 app[web.1]: at Module.load (module.js:561:32)
2019-09-03T15:13:15.611244+00:00 app[web.1]: at tryModuleLoad (module.js:501:12)
2019-09-03T15:13:15.611246+00:00 app[web.1]: at Function.Module._load (module.js:493:3)
2019-09-03T15:13:15.611248+00:00 app[web.1]: at Module.require (module.js:593:17)
2019-09-03T15:13:15.611250+00:00 app[web.1]: at require (internal/module.js:11:18)
2019-09-03T15:13:15.611252+00:00 app[web.1]: at Object.<anonymous> (/app/utils/index.js:14:28)
2019-09-03T15:13:15.611253+00:00 app[web.1]: at Module._compile (module.js:649:30)
2019-09-03T15:13:15.611256+00:00 app[web.1]: at Object.Module._extensions..js (module.js:660:10)
2019-09-03T15:13:15.611258+00:00 app[web.1]: at Module.load (module.js:561:32)
2019-09-03T15:13:15.649451+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2019-09-03T15:13:15.652527+00:00 app[web.1]: npm ERR! errno 1
2019-09-03T15:13:15.663204+00:00 app[web.1]: npm ERR! paulandbarnabas@1.0.0 start: `node app.js`
2019-09-03T15:13:15.663463+00:00 app[web.1]: npm ERR! Exit status 1
2019-09-03T15:13:15.663809+00:00 app[web.1]: npm ERR!
2019-09-03T15:13:15.664059+00:00 app[web.1]: npm ERR! Failed at the paulandbarnabas@1.0.0 start script.
2019-09-03T15:13:15.667959+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2019-09-03T15:13:15.696266+00:00 app[web.1]: 
2019-09-03T15:13:15.697366+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2019-09-03T15:13:15.697849+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2019-09-03T15_13_15_670Z-debug.log

我不知道这些错误是否相关。

我已经尝试重建...我在 package.json 中丢失了一些包,修复了这些...删除了未使用的包,几乎所有内容。我什至两次删除了该应用程序并在 Heroku 上重新开始,但运气不好。这是我的 package.json。

{
  "name": "paulandbarnabas",
  "version": "1.0.0",
  "description": "",
  "main": "app.js",
  "scripts": {
    "start": "node app.js"
  },
  "engines": {
    "node": "9.9.0"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "app-root-path": "^2.2.1",
    "bcrypt": "^3.0.6",
    "body-parser": "^1.19.0",
    "dot-prop": "^5.1.0",
    "dynamic-url-constructor": "^1.0.4",
    "express": "^4.17.1",
    "express-session": "^1.16.2",
    "http-status-codes": "^1.3.2",
    "iso-639-1": "^2.1.0",
    "iso-639-2-english": "^1.0.0",
    "jquery": "^3.4.1",
    "lodash": "^4.17.15",
    "moment": "^2.24.0",
    "mongodb": "^3.3.2",
    "mongoose": "^5.6.11",
    "mongoose-unique-validator": "^2.0.3",
    "morgan": "^1.9.1",
    "mustache": "^3.0.3",
    "pug": "^2.0.4",
    "rsvp": "^4.8.5",
    "timepicker": "^1.11.15",
    "validate.js": "^0.12.0",
    "winston": "^3.2.1",
    "yargs": "^12.0.5"
  },
  "devDependencies": {
    "browserify": "^16.5.0",
    "chai": "^4.2.0",
    "event-stream": "^4.0.1",
    "expect.js": "^0.3.1",
    "gulp": "^3.9.1",
    "gulp-autoprefixer": "^6.1.0",
    "gulp-csso": "^3.0.1",
    "gulp-nodemon": "^2.4.2",
    "gulp-rename": "^1.4.0",
    "gulp-sass": "^4.0.2",
    "mocha": "^5.2.0",
    "mock-req-res": "^1.1.1",
    "pump": "^3.0.0",
    "sinon": "^7.4.2",
    "sinon-chai": "^3.3.0",
    "supertest": "^3.4.2",
    "supertest-session": "^3.3.0",
    "vinyl-source-stream": "^2.0.0"
  }
}

这是启动文件,app.js

const path = require('path');
const http = require('http');
const yargs = require('yargs');
const morgan = require('morgan');
const express = require('express');
const bodyParser = require('body-parser');
const session = require('express-session');
const HttpStatus = require('http-status-codes');

const routes = require('./routes');
const {logger, PBURLConstructor} = require('./utils');
const config = require('./config/config');
const constants = require('./config/constants');
const ajaxRouter = require('./ajax/routes/ajax-gateway-router');

/**
 * Parse command line arguemnts with yargs
 */
yargs
  .option('seed', {
    alias: 's',
    describe: 'Wipe and seed database with data defined in dev/seed'
  })
  .help();
// Arguments
let argv = yargs.argv;

(async argv => {
   // Seed database if in development
   if(process.env.NODE_ENV === 'development'){
    let seed = (argv.seed || argv._[0] === 'seed');
    await require('./dev/seed-database').init(seed);
  }
})(argv);

/**
 * Create HTTP Server and Express
 */
let app = express();
let server = http.createServer(app);

/**
 * Pug and View Engine
 */
app.set('view engine', 'pug');
app.set('views', __dirname + '/views');

/**
 * Middleware
 */
// Static Server
 app.use(express.static(__dirname + '/public'))
 // Body Parser
 app.use(bodyParser.urlencoded({extended: false}));
 app.use(bodyParser.json());
 // FIXME: Make session secret an env var
 // Session
 app.use(session({secret: 'julianiscool', saveUninitialized: false, resave: false}));
 // Add constants and config vars to all render params
 app.use((req, res, next) => {
   res.locals.constants = constants;
   app.locals.moment = require('moment');
   res.locals.PBURLConstructor = PBURLConstructor;
   next();
 });
 // Morgan HTTP logger
 app.use(morgan('tiny', {
   // skip logging if in test mode
   skip: (req, res) => {
     return process.env.NODE_ENV == 'test';
   }
 }));
 // // Express json
 app.use(express.json());

/**
 * Express Routing
 */
  // Landing page (Login Page)
  app.use('/', routes.loginRoute);

  // AJAX Requests
  app.use('/ajax', ajaxRouter);

  // Sign Up
  app.use('/register', routes.registrationRoute);

  // Dashboard
  app.use('/dashboard', routes.dashboardRoute);

  // Admin Panel
  app.use('/admin-panel', routes.adminPanelRoute);

  // User Territory CRUD
  app.use('/fragment', routes.fragmentRoute);

  // Error Handler
  app.use((err, req, res, next) => {

   console.error(err);
   res.status(HttpStatus.INTERNAL_SERVER_ERROR).send();

  });

  // Start express server
  server.listen(process.env.PORT, ()=>{

    logger.info(`"${constants.site_name}" live on port ${process.env.PORT}`);

  });

module.exports = {app, server};

这是来自部署的日志(安装了dynamic-url-constructor)

Counting objects: 1, done.
Writing objects: 100% (1/1), 185 bytes | 0 bytes/s, done.
Total 1 (delta 0), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote: 
remote: -----> Node.js app detected
remote:        
remote: -----> Creating runtime environment
remote:        
remote:        NPM_CONFIG_LOGLEVEL=error
remote:        NODE_ENV=devlopment
remote:        NODE_MODULES_CACHE=false
remote:        NODE_VERBOSE=true
remote:        
remote: -----> Installing binaries
remote:        engines.node (package.json):  9.9.0
remote:        engines.npm (package.json):   unspecified (use default)
remote:        
remote:        Resolving node version 9.9.0...
remote:        Downloading and installing node 9.9.0...
remote:        Using default npm version: 5.6.0
remote:        
remote: -----> Restoring cache
remote:        Caching has been disabled because NODE_MODULES_CACHE=false
remote:        
remote: -----> Installing dependencies
remote:        Installing node modules (package.json + package-lock)
remote:        
remote:        > node-sass@4.9.4 install /tmp/build_9729a24074237ff35fe86fb84a02a861/node_modules/node-sass
remote:        > node scripts/install.js
remote:        
remote:        Downloading binary from https://github.com/sass/node-sass/releases/download/v4.9.4/linux-x64-59_binding.node
remote:        Download complete
remote:        Binary saved to /tmp/build_9729a24074237ff35fe86fb84a02a861/node_modules/node-sass/vendor/linux-x64-59/binding.node
remote:        Caching binary to /tmp/npmcache.v0UPk/node-sass/4.9.4/linux-x64-59_binding.node
remote:        
remote:        > bcrypt@3.0.6 install /tmp/build_9729a24074237ff35fe86fb84a02a861/node_modules/bcrypt
remote:        > node-pre-gyp install --fallback-to-build
remote:        
remote:        [bcrypt] Success: "/tmp/build_9729a24074237ff35fe86fb84a02a861/node_modules/bcrypt/lib/binding/bcrypt_lib.node" is installed via remote
remote:        
remote:        > core-js@2.6.9 postinstall /tmp/build_9729a24074237ff35fe86fb84a02a861/node_modules/core-js
remote:        > node scripts/postinstall || echo "ignore"
remote:        
remote:        
remote:        > nodemon@1.19.1 postinstall /tmp/build_9729a24074237ff35fe86fb84a02a861/node_modules/nodemon
remote:        > node bin/postinstall || exit 0
remote:        
remote:        Love nodemon? You can now support the project via the open collective:
remote:         > https://opencollective.com/nodemon/donate
remote:        
remote:        
remote:        > node-sass@4.9.4 postinstall /tmp/build_9729a24074237ff35fe86fb84a02a861/node_modules/node-sass
remote:        > node scripts/build.js
remote:        
remote:        Binary found at /tmp/build_9729a24074237ff35fe86fb84a02a861/node_modules/node-sass/vendor/linux-x64-59/binding.node
remote:        Testing binary
remote:        Binary is fine
remote:        added 1045 packages in 21.274s
remote:        
remote: -----> Build
remote:        
remote: -----> Pruning devDependencies
remote:        Skipping because NODE_ENV is not 'production'
remote:        
remote: -----> Build succeeded!
remote:        ├── app-root-path@2.2.1
remote:        ├── bcrypt@3.0.6
remote:        ├── body-parser@1.19.0
remote:        ├── browserify@16.5.0
remote:        ├── chai@4.2.0
remote:        ├── dot-prop@5.1.0
remote:        ├── dynamic-url-constructor@1.0.4
remote:        ├── event-stream@4.0.1
remote:        ├── expect.js@0.3.1
remote:        ├── express@4.17.1
remote:        ├── express-session@1.16.2
remote:        ├── gulp@3.9.1
remote:        ├── gulp-autoprefixer@6.1.0
remote:        ├── gulp-csso@3.0.1
remote:        ├── gulp-nodemon@2.4.2
remote:        ├── gulp-rename@1.4.0
remote:        ├── gulp-sass@4.0.2
remote:        ├── http-status-codes@1.3.2
remote:        ├── iso-639-1@2.1.0
remote:        ├── iso-639-2-english@1.0.0
remote:        ├── jquery@3.4.1
remote:        ├── lodash@4.17.15
remote:        ├── mocha@5.2.0
remote:        ├── mock-req-res@1.1.1
remote:        ├── moment@2.24.0
remote:        ├── mongodb@3.3.2
remote:        ├── mongoose@5.6.11
remote:        ├── mongoose-unique-validator@2.0.3
remote:        ├── morgan@1.9.1
remote:        ├── mustache@3.0.3
remote:        ├── process@0.11.10
remote:        ├── pug@2.0.4
remote:        ├── pump@3.0.0
remote:        ├── rsvp@4.8.5
remote:        ├── sinon@7.4.2
remote:        ├── sinon-chai@3.3.0
remote:        ├── supertest@3.4.2
remote:        ├── supertest-session@3.3.0
remote:        ├── timepicker@1.11.15
remote:        ├── validate.js@0.12.0
remote:        ├── vinyl-source-stream@2.0.0
remote:        ├── winston@3.2.1
remote:        └── yargs@12.0.5
remote:        
remote: -----> Discovering process types
remote:        Procfile declares types     -> (none)
remote:        Default types for buildpack -> web
remote: 
remote: -----> Compressing...
remote:        Done: 38.7M
remote: -----> Launching...
remote:        Released v27
remote:        https://paul-and-barnabas.herokuapp.com/ deployed to Heroku
remote: 
remote: Verifying deploy... done.
To https://git.heroku.com/paul-and-barnabas.git
   d060199..3640066  HEAD -> master

一切都在本地无缝运行。

我被难住了。

【问题讨论】:

  • app.js 中有什么内容?
  • @Chris 我编辑了问题以包含 app.js 的内容
  • 除了“退出状态1”之外没有其他相关输出了吗?我建议您在代码中添加一些日志记录输出。在 Heroku 上,您打印到 stdoutstderr 的任何内容都将被捕获到日志流中。
  • @Chris 感谢您的快速回复!我应该在哪里注销?我什至无法辨别错误的位置。我认为它必须对 npm 和我的依赖项做一些事情
  • 啊,这里有更多信息。您完全确定您向我们展示了正确的package.json 吗?看起来 dynamic-url-constructor 没有安装在 Heroku 上。在出现错误之前,您是否看到它已安装在您的部署输出中?

标签: node.js heroku npm


【解决方案1】:

好的,所以我终于找到了问题所在。经过更多挖掘后,我发现了NPM_CONFIG_LOGLEVEL heroku config var,当设置为verbose 时,它将提供更详细的日志。之后我将NODE_ENV 切换回production 并尝试再次部署。我在dynamic-url-constructor 上再次遇到“找不到模块”错误。在对可能导致该错误的不同事物进行了更多挖掘之后,区分大小写是我在其他项目中遇到的问题,因为我的开发机器的文件系统 MAC OSX 不区分大小写。

这是踢球者,我是这个模块的作者,它实际上是发布到 NPM 的。 https://www.npmjs.com/package/dynamic-url-constructor

package.json 中的main 键指定的文件与实际文件的大小写不匹配。在修复了我自己的模块、发布、更新依赖和重新部署之后,尽管出现了一个模糊的错误,我终于成功地开始了。

【讨论】:

    猜你喜欢
    • 2015-07-22
    • 2019-06-15
    • 1970-01-01
    • 1970-01-01
    • 2016-04-07
    • 1970-01-01
    • 2017-11-04
    • 1970-01-01
    • 2015-04-05
    相关资源
    最近更新 更多