node.js - 无法使用 npm 脚本推送到 heroku master "postinstall"

标签 node.js reactjs heroku webpack gulp

我有一个 postinstall 脚本,我假设每当您执行 git push heroku master 时都会调用该脚本。但由于某种原因,推送失败了。我在 Windows 上,必须对某些脚本使用 cross-env 包。我认为这可能会导致它失败,但我不确定。

这是终端输出的图像: image

Heroku 日志位于底部

以下是脚本:

"build": "cross-env NODE_ENV=production webpack && gulp",
"postinstall": "npm run build"

以下是 webpack 和 gulp 文件:

const webpack = require('webpack');
const path = require('path');

module.exports = {
  entry: {
    app: './src/app.js',
  },
  output: {
    filename: 'public/build/bundle.js',
    sourceMapFilename: 'public/build/bundle.map',
  },
  devtool: '#source-map',
  plugins:
    process.env.NODE_ENV === 'production'
      ? [
          new webpack.DefinePlugin({
            'process.env': {
              NODE_ENV: JSON.stringify('production'),
            },
          }),
          new webpack.optimize.UglifyJsPlugin({
            minimize: true,
            compress: {
              warnings: true,
            },
          }),
        ]
      : [],
  module: {
    loaders: [
      {
        test: /\.jsx?$/,
        exclude: /(node_modules)/,
        loader: 'babel-loader',
        query: {
          presets: ['react', 'es2015', 'stage-1'],
        },
      },
    ],
  },
};
<小时/>
var gulp = require('gulp');
var less = require('gulp-less');
var gp_concat = require('gulp-concat');
var gp_rename = require('gulp-rename');
var gp_uglify = require('gulp-uglify');
var minifyCSS = require('gulp-minify-css');
var autoprefixer = require('gulp-autoprefixer');
var path = require('path');

gulp.task('css', () => {
  return gulp
    .src([
      './public/assets/css/font-awesome.main.css',
      './public/assets/css/ie8.css',
      './public/assets/css/main.css'
    ])
    .pipe(minifyCSS())
    .pipe(autoprefixer('last 2 version', 'safari 5', 'ie 8', 'ie 9'))
    .pipe(gp_concat('style.min.css'))
    .pipe(gulp.dest('./public/build/css'));
});

gulp.task('build', () => {
  return gulp
    .src([
      './public/assets/js/jquery.min.js',
      './public/assets/js/jquery.poptrox.min.js',
      './public/assets/js/skel.min.js',
      './public/assets/js/util.js',
      './public/assets/js/ie/respond.min.js',
      './public/assets/js/main.js'
    ])
    .pipe(gp_concat('gulp-concat.js'))
    .pipe(gulp.dest('./public/min'))
    .pipe(gp_rename('vendor.min.js'))
    .pipe(gp_uglify())
    .pipe(gulp.dest('./public/build/'));
});

gulp.task('default', ['css', 'build'], () => {});
<小时/>
2017-09-18T13:55:31.499365+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2017-09-18T13:55:31.499511+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2017-09-18T13_55_31_493Z-debug.log
2017-09-18T13:55:31.615780+00:00 heroku[web.1]: Process exited with status 1
2017-09-18T13:55:33.147165+00:00 app[web.1]:
2017-09-18T13:55:33.147188+00:00 app[web.1]: > snapshot@0.0.0 start /app
2017-09-18T13:55:33.147189+00:00 app[web.1]: > node ./bin/www
2017-09-18T13:55:33.147190+00:00 app[web.1]:
2017-09-18T13:55:33.760733+00:00 app[web.1]: /app/node_modules/client-sessions/lib/client-sessions.js:548
2017-09-18T13:55:33.760762+00:00 app[web.1]:     throw new Error("cannot set up sessions without a secret "+
2017-09-18T13:55:33.760764+00:00 app[web.1]:     ^
2017-09-18T13:55:33.760765+00:00 app[web.1]:
2017-09-18T13:55:33.760770+00:00 app[web.1]: Error: cannot set up sessions without a secret or encryptionKey/signatureKe
y pair
2017-09-18T13:55:33.760770+00:00 app[web.1]:     at clientSessionFactory (/app/node_modules/client-sessions/lib/client-s
essions.js:548:11)
2017-09-18T13:55:33.760771+00:00 app[web.1]:     at Object.<anonymous> (/app/app.js:35:3)
2017-09-18T13:55:33.760771+00:00 app[web.1]:     at Module._compile (module.js:570:32)
2017-09-18T13:55:33.760772+00:00 app[web.1]:     at Object.Module._extensions..js (module.js:579:10)
2017-09-18T13:55:33.760772+00:00 app[web.1]:     at Module.load (module.js:487:32)
2017-09-18T13:55:33.760773+00:00 app[web.1]:     at tryModuleLoad (module.js:446:12)
2017-09-18T13:55:33.760773+00:00 app[web.1]:     at Function.Module._load (module.js:438:3)
2017-09-18T13:55:33.760774+00:00 app[web.1]:     at require (internal/module.js:20:19)
2017-09-18T13:55:33.760773+00:00 app[web.1]:     at Module.require (module.js:497:17)
2017-09-18T13:55:33.760774+00:00 app[web.1]:     at Object.<anonymous> (/app/bin/www:7:11)
2017-09-18T13:55:33.760775+00:00 app[web.1]:     at Module._compile (module.js:570:32)
2017-09-18T13:55:33.760775+00:00 app[web.1]:     at Object.Module._extensions..js (module.js:579:10)
2017-09-18T13:55:33.760775+00:00 app[web.1]:     at Module.load (module.js:487:32)
2017-09-18T13:55:33.760776+00:00 app[web.1]:     at Function.Module._load (module.js:438:3)
2017-09-18T13:55:33.760776+00:00 app[web.1]:     at tryModuleLoad (module.js:446:12)
2017-09-18T13:55:33.760776+00:00 app[web.1]:     at Module.runMain (module.js:604:10)
2017-09-18T13:55:33.760777+00:00 app[web.1]:     at run (bootstrap_node.js:389:7)
2017-09-18T13:55:33.760777+00:00 app[web.1]:     at startup (bootstrap_node.js:149:9)
2017-09-18T13:55:33.760778+00:00 app[web.1]:     at bootstrap_node.js:502:3
2017-09-18T13:55:33.774695+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2017-09-18T13:55:33.775459+00:00 app[web.1]: npm ERR! errno 1
2017-09-18T13:55:33.776542+00:00 app[web.1]: npm ERR! snapshot@0.0.0 start: `node ./bin/www`
2017-09-18T13:55:33.776626+00:00 app[web.1]: npm ERR! Exit status 1
2017-09-18T13:55:33.776766+00:00 app[web.1]: npm ERR!
2017-09-18T13:55:33.776875+00:00 app[web.1]: npm ERR! Failed at the snapshot@0.0.0 start script.
2017-09-18T13:55:33.776951+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additiona
l logging output above.
2017-09-18T13:55:33.783741+00:00 app[web.1]:
2017-09-18T13:55:33.783984+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2017-09-18T13:55:33.784118+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2017-09-18T13_55_33_780Z-debug.log
2017-09-18T13:55:33.871079+00:00 heroku[web.1]: Process exited with status 1
2017-09-18T13:55:33.883665+00:00 heroku[web.1]: State changed from starting to crashed
2017-09-18T13:55:52.250660+00:00 heroku[web.1]: State changed from crashed to starting
2017-09-18T13:55:52.048172+00:00 app[api]: Set SESSION_SECRET config vars by user tbaustin1992@gmail.com
2017-09-18T13:55:52.048172+00:00 app[api]: Release v7 created by user tbaustin1992@gmail.com
2017-09-18T13:55:55.840695+00:00 heroku[web.1]: Starting process with command `npm start`
2017-09-18T13:55:58.323084+00:00 app[web.1]:
2017-09-18T13:55:58.323119+00:00 app[web.1]: > snapshot@0.0.0 start /app
2017-09-18T13:55:58.323120+00:00 app[web.1]: > node ./bin/www
2017-09-18T13:55:58.323121+00:00 app[web.1]:
2017-09-18T13:55:58.990350+00:00 app[web.1]: (node:18) DeprecationWarning: `open()` is deprecated in mongoose >= 4.11.0,
 use `openUri()` instead, or set the `useMongoClient` option if using `connect()` or `createConnection()`. See http://mo
ngoosejs.com/docs/connections.html#use-mongo-client
2017-09-18T13:55:59.019980+00:00 app[web.1]: Db.prototype.authenticate method will no longer be available in the next ma
jor release 3.x as MongoDB 3.6 will only allow auth against users in the admin db and will no longer allow multiple cred
entials on a socket. Please authenticate using MongoClient.connect with auth credentials.
2017-09-18T13:55:59.068033+00:00 app[web.1]: DB CONNECT SUCCESS
2017-09-18T13:55:59.698175+00:00 heroku[web.1]: State changed from starting to up
2017-09-18T13:56:08.437795+00:00 heroku[router]: at=info method=GET path="/assets/js/main.js" host=ta-snapshot.herokuapp
.com request_id=a6710e07-a8f0-4745-9e1c-a235cb2a0252 fwd="24.192.32.162" dyno=web.1 connect=1ms service=6ms status=200 b
ytes=3324 protocol=https
2017-09-18T13:56:08.297473+00:00 heroku[router]: at=info method=GET path="/" host=ta-snapshot.herokuapp.com request_id=b
947354f-896e-464c-aadc-fc02cfc839e1 fwd="24.192.32.162" dyno=web.1 connect=1ms service=39ms status=200 bytes=1680 protoc
ol=https
2017-09-18T13:56:08.438162+00:00 heroku[router]: at=info method=GET path="/assets/js/util.js" host=ta-snapshot.herokuapp
.com request_id=bf8023a7-3cb1-4747-bd3c-a1ffaf1b723c fwd="24.192.32.162" dyno=web.1 connect=0ms service=6ms status=200 b
ytes=12722 protocol=https
2017-09-18T13:56:08.437227+00:00 heroku[router]: at=info method=GET path="/assets/js/skel.min.js" host=ta-snapshot.herok
uapp.com request_id=71672b98-4aa0-4afd-81ea-6fb051a8c62f fwd="24.192.32.162" dyno=web.1 connect=1ms service=6ms status=2
00 bytes=9373 protocol=https
2017-09-18T13:56:08.366497+00:00 heroku[router]: at=info method=GET path="/assets/js/jquery.min.js" host=ta-snapshot.her
okuapp.com request_id=1a37732e-e61e-49ac-b987-51eb0ea99e9e fwd="24.192.32.162" dyno=web.1 connect=1ms service=22ms statu
s=200 bytes=96247 protocol=https
2017-09-18T13:56:08.298920+00:00 app[web.1]: GET / 200 26.782 ms - 1477
2017-09-18T13:56:08.361855+00:00 app[web.1]: GET /assets/css/main.css 200 12.223 ms - 50410
2017-09-18T13:56:08.366349+00:00 app[web.1]: GET /assets/js/jquery.min.js 200 1.785 ms - 95957
2017-09-18T13:56:08.432865+00:00 app[web.1]: GET /assets/js/jquery.poptrox.min.js 200 1.283 ms - 12113
2017-09-18T13:56:08.435508+00:00 app[web.1]: GET /assets/js/skel.min.js 200 3.256 ms - 9085
2017-09-18T13:56:08.437044+00:00 app[web.1]: GET /assets/js/util.js 200 2.149 ms - 12433
2017-09-18T13:56:08.494412+00:00 app[web.1]: GET /build/bundle.js 200 1.214 ms - 1577443
2017-09-18T13:56:08.437610+00:00 app[web.1]: GET /assets/js/main.js 200 2.387 ms - 3037
2017-09-18T13:56:08.364794+00:00 heroku[router]: at=info method=GET path="/assets/css/main.css" host=ta-snapshot.herokua
pp.com request_id=ff43a00a-5fcf-4a41-b0f3-a971d06bac90 fwd="24.192.32.162" dyno=web.1 connect=1ms service=20ms status=20
0 bytes=50700 protocol=https
2017-09-18T13:56:08.434158+00:00 heroku[router]: at=info method=GET path="/assets/js/jquery.poptrox.min.js" host=ta-snap
shot.herokuapp.com request_id=83fd62f8-f6cc-486b-bf4b-4041a275a249 fwd="24.192.32.162" dyno=web.1 connect=1ms service=3m
s status=200 bytes=12402 protocol=https
2017-09-18T13:56:08.518895+00:00 heroku[router]: at=info method=GET path="/build/bundle.js" host=ta-snapshot.herokuapp.c
om request_id=2dd801e9-e899-4d4a-8a52-dc1fc67b613c fwd="24.192.32.162" dyno=web.1 connect=1ms service=44ms status=200 by
tes=1577736 protocol=https
2017-09-18T13:56:09.148354+00:00 app[web.1]: GET /assets/css/font-awesome.min.css 200 4.151 ms - 29063
2017-09-18T13:56:09.146219+00:00 heroku[router]: at=info method=GET path="/assets/css/font-awesome.min.css" host=ta-snap
shot.herokuapp.com request_id=39dfd327-c09a-45e4-855a-ebffaa27257c fwd="24.192.32.162" dyno=web.1 connect=1ms service=8m
s status=200 bytes=29353 protocol=https
2017-09-18T13:56:09.517771+00:00 app[web.1]: GET /account/currentuser 200 3.193 ms - 38
2017-09-18T13:56:09.548178+00:00 app[web.1]: GET /api/post?lat=40.7504753&lng=-73.9932668 200 26.721 ms - 39
2017-09-18T13:56:09.513895+00:00 heroku[router]: at=info method=GET path="/account/currentuser" host=ta-snapshot.herokua
pp.com request_id=65c8a776-9d5a-47fd-b477-db435f78b797 fwd="24.192.32.162" dyno=web.1 connect=1ms service=7ms status=200
 bytes=245 protocol=https
2017-09-18T13:56:09.549304+00:00 heroku[router]: at=info method=GET path="/api/post?lat=40.7504753&lng=-73.9932668" host
=ta-snapshot.herokuapp.com request_id=16272576-6b17-4106-8836-afe0ce8bb34e fwd="24.192.32.162" dyno=web.1 connect=1ms se
rvice=33ms status=200 bytes=246 protocol=https
2017-09-18T13:56:10.263855+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=ta-snapshot.herokuapp.com r
equest_id=2a88ed05-0fad-4990-b29a-30ab227c02fc fwd="24.192.32.162" dyno=web.1 connect=1ms service=15ms status=404 bytes=
248 protocol=https
2017-09-18T13:56:10.259213+00:00 app[web.1]: GET /favicon.ico 404 9.124 ms - 41
2017-09-18T13:56:28.009172+00:00 heroku[router]: at=info method=POST path="/account/register" host=ta-snapshot.herokuapp
.com request_id=cf25e1dc-d704-4ea4-a4c0-f0688fdf8f83 fwd="24.192.32.162" dyno=web.1 connect=1ms service=241ms status=200
 bytes=569 protocol=https
2017-09-18T13:56:28.001827+00:00 app[web.1]: { __v: 0,
2017-09-18T13:56:28.001851+00:00 app[web.1]:   _id: 59bfd08b43dd250012c92e1e,
2017-09-18T13:56:28.001852+00:00 app[web.1]:   timestamp: 2017-09-18T13:56:27.968Z,
2017-09-18T13:56:28.001853+00:00 app[web.1]:   password: '$2a$10$70PiciKOFgd04G090zECtOGH2ufENQk7/3vDFkc3x0QgTdNEc8k72',
2017-09-18T13:56:28.001854+00:00 app[web.1]:   username: 'tbaustin' }
2017-09-18T13:56:28.008043+00:00 app[web.1]: POST /account/register 200 238.870 ms - 128
2017-09-18T13:56:44.301208+00:00 app[web.1]: GET /api/post?lat=40.75076789772389&lng=-73.99052021796876 200 13.201 ms -
39
2017-09-18T13:56:44.302363+00:00 heroku[router]: at=info method=GET path="/api/post?lat=40.75076789772389&lng=-73.990520
21796876" host=ta-snapshot.herokuapp.com request_id=6b8e57d1-543d-4b0d-9447-28a7861c365a fwd="24.192.32.162" dyno=web.1
connect=1ms service=18ms status=200 bytes=246 protocol=https
2017-09-18T13:56:45.284274+00:00 heroku[router]: at=info method=GET path="/api/post?lat=40.75219835694907&lng=-73.993953
44550783" host=ta-snapshot.herokuapp.com request_id=9472bd9e-c88b-4ca0-888f-ba65dbc3cf83 fwd="24.192.32.162" dyno=web.1
connect=1ms service=13ms status=200 bytes=246 protocol=https
2017-09-18T13:56:45.284477+00:00 app[web.1]: GET /api/post?lat=40.75219835694907&lng=-73.99395344550783 200 10.603 ms -
39
2017-09-18T13:56:47.609169+00:00 heroku[router]: at=info method=GET path="/api/post?lat=40.75920391164151&lng=-73.990541
67564088" host=ta-snapshot.herokuapp.com request_id=2ba05865-34bf-433a-a6ba-388fcddfa95a fwd="24.192.32.162" dyno=web.1
connect=1ms service=10ms status=200 bytes=246 protocol=https
2017-09-18T13:56:47.607576+00:00 app[web.1]: GET /api/post?lat=40.75920391164151&lng=-73.99054167564088 200 4.460 ms - 3
9
2017-09-18T13:57:12.601209+00:00 app[web.1]: POST /api/post 200 31.164 ms - 341
2017-09-18T13:57:12.604731+00:00 heroku[router]: at=info method=POST path="/api/post" host=ta-snapshot.herokuapp.com req
uest_id=cb2ae99f-745c-460b-ac31-8c12fe476a40 fwd="24.192.32.162" dyno=web.1 connect=4ms service=37ms status=200 bytes=55
0 protocol=https
2017-09-18T14:33:24.565734+00:00 heroku[web.1]: Idling
2017-09-18T14:33:24.567184+00:00 heroku[web.1]: State changed from up to down
2017-09-18T14:33:25.533659+00:00 app[web.1]: Error waiting for process to terminate: No child processes
2017-09-18T14:33:25.472561+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2017-09-18T14:33:25.653495+00:00 heroku[web.1]: Process exited with status 22
2017-09-20T15:41:00.000000+00:00 app[api]: Build started by user tbaustin1992@gmail.com
2017-09-20T15:41:00.000000+00:00 app[api]: Build failed -- check your build logs

最佳答案

根据@skwidbreth提供,我在heroku日志中收到了session_secret错误。我想它没有以某种方式提供或定义。我在 .env 文件和 heroku 的配置变量中定义了它,但它仍然不起作用。

通过更改 webpack 文件以包含 SESSION_SECRET 来实现此目的。我将发布新的 webpack.config.js

您可以在 process.env 旁边看到我按照建议放置的位置。

const webpack = require('webpack');
const path = require('path');

module.exports = {
  entry: {
    app: './src/app.js',
  },
  output: {
    filename: 'public/build/bundle.js',
    sourceMapFilename: 'public/build/bundle.map',
  },
  devtool: '#source-map',
  plugins:
    process.env.NODE_ENV === 'production'
      ? [
          new webpack.DefinePlugin({
            'process.env': {
              NODE_ENV: JSON.stringify('production'),
            },
            SESSION_SECRET: JSON.stringify(process.env.SESSION_SECRET),
          }),
          new webpack.optimize.UglifyJsPlugin({
            minimize: true,
            compress: {
              warnings: true,
            },
          }),
        ]
      : [],
  module: {
    loaders: [
      {
        test: /\.jsx?$/,
        exclude: /(node_modules)/,
        loader: 'babel-loader',
        query: {
          presets: ['react', 'es2015', 'stage-1'],
        },
      },
    ],
  },
};

关于node.js - 无法使用 npm 脚本推送到 heroku master "postinstall",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46326524/

相关文章:

带有 ZeroMQ + Socket.io + 每个客户端范围的 Node.js

javascript - 如何为纯 JavaScript react 组件正确定义 *.d.ts(类型)文件

git - Heroku 登录在 git bash 中无法正常工作

reactjs - 生产中的 Dotenv-webpack?

ruby-on-rails - 强制 Rails Heroku 应用程序从 subdomain.herokuapp.com 到顶点域?

javascript - 访问调用模块中定义的所需模块中的函数

node.js - Mongodb - 小写查找

node.js - 我需要为 MongoDB 启用身份验证吗?

javascript - 当到达存储在数据库中的 future 日期、时间时,如何在 Node JS 中触发事件?

javascript - 有没有办法使用react-leaflet添加MultiPolyline组件?