在Heroku上启动与webpack和babel-loader相关的Node / Koa应用程序时出错

时间:2017-02-27 19:15:27

标签: node.js heroku webpack babeljs

我已经使用Node.js和Koa构建了一个小应用程序。我正在使用Cloud9 IDE,我可以直接从Cloud 9运行我的应用程序,没有任何问题。我正在尝试部署到Heroku(通过github)。但是,我在Heroku上启动应用程序时收到错误,我无法修复。我认为这是一个问题,我如何设置目录和Heroku找不到依赖模块,但我是Node / Koa的新手,无法弄清楚如何纠正这一点。我的代码在这里:https://github.com/infornite/n4nite-api

来自Heroku的错误记录: enter image description here

Webpack.config.js

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

const externals = fs.readdirSync('node_modules')
    .filter(x => ['.bin'].indexOf(x) === -1)
    .reduce((obj, mod) => {
        obj[mod] = 'commonjs ' + mod;
        return obj;
    }, {});

externals['koa-neo4j/check'] = 'commonjs koa-neo4j/check';
externals['koa-neo4j/preprocess'] = 'commonjs koa-neo4j/preprocess';
externals['koa-neo4j/postprocess'] = 'commonjs koa-neo4j/postprocess';
externals['koa-neo4j/debug'] = 'commonjs koa-neo4j/debug';
externals['koa-neo4j/util'] = 'commonjs koa-neo4j/util';

const plugins = [];

const config = {
    target: 'node',
    entry: {
        './server': './src/server.js'
    },
    devtool: 'source-map',
    output: {
        path: './',
        filename: '[name].js',
        library: '[name]',
        libraryTarget: 'umd',
        umdNamedDefine: true
    },
    externals: externals,
    module: {
        rules: [
            {
                test: /\.jsx?$/,
                exclude: /(node_modules)/,
                loader: 'babel-loader'
            }
        ]
    },
    resolve: {
        extensions: ['.js']
    },
    plugins: plugins
};

module.exports = config;

的package.json

{
  "name": "n4nite-api",
  "version": "0.1.0",
  "description": "An API for the Infornite Metadata Management Tool",
  "credits": "koa-neo4j-starter-kit / Keyvan Mir Mohammad Sadeghi <keyvan.m.sadeghi@gmail.com>",
  "main": "server.js",
  "jsnext:main": "./src/server.js",
  "scripts": {
    "lint": "./node_modules/.bin/eslint ./src --fix",
    "dev": "./node_modules/.bin/webpack --progress --colors --watch",
    "build": "./node_modules/.bin/webpack",
    "start": "npm run build && DEV=1 node $NODE_DEBUG_OPTION server.js",
    "serve": "npm run build && node server.js"
  },
  "author": "Keyvan Mir Mohammad Sadeghi <keyvan.m.sadeghi@gmail.com>",
  "devDependencies": {
    "babel": "^6.5.2",
    "babel-cli": "^6.11.4",
    "babel-core": "^6.13.2",
    "babel-eslint": "^6.1.2",
    "babel-loader": "^6.2.4",
    "babel-plugin-add-module-exports": "^0.2.1",
    "babel-plugin-syntax-async-functions": "^6.13.0",
    "babel-plugin-syntax-object-rest-spread": "^6.13.0",
    "babel-plugin-transform-es2015-arrow-functions": "^6.8.0",
    "babel-plugin-transform-es2015-destructuring": "^6.9.0",
    "babel-plugin-transform-es2015-for-of": "^6.8.0",
    "babel-plugin-transform-es2015-modules-commonjs": "^6.14.0",
    "babel-plugin-transform-es2015-modules-umd": "^6.12.0",
    "babel-plugin-transform-es2015-parameters": "^6.11.4",
    "babel-plugin-transform-es2015-spread": "^6.8.0",
    "babel-plugin-transform-object-rest-spread": "^6.8.0",
    "babel-plugin-transform-regenerator": "^6.14.0",
    "babel-plugin-transform-runtime": "^6.12.0",
    "babel-plugin-transform-strict-mode": "^6.11.3",
    "babel-preset-es2015": "^6.6.0",
    "babel-preset-stage-0": "^6.5.0",
    "babel-register": "^6.7.2",
    "coffee-loader": "^0.7.2",
    "eslint": "^3.3.1",
    "eslint-loader": "^1.5.0",
    "eslint-plugin-babel": "^3.3.0",
    "webpack": "^2.1.0-beta.27"
  },
  "dependencies": {
    "koa-neo4j": "^1.0.0"
  }
}

1 个答案:

答案 0 :(得分:1)

默认情况下,Heroku不会安装devDependenciesNode.js devDependencies)。您有几种可能解决该问题:

  • 将必要的依赖项放在dependencies而不是devDependencies
  • 使用以下内容禁用生产模式:heroku config:set NPM_CONFIG_PRODUCTION=false
  • 在本地构建并直接推送构建的文件。

选择您喜欢的那个,但通常最好在本地构建它,这样您就不需要在部署时安装所有依赖项。