0

尝试将 react_on_rails 应用程序部署到 heroku 时。我收到以下一系列错误。在本地一切正常,但是当我尝试部署到 heroku 时,我得到:

ERROR in ./app/bundles/appbundle/startup/MyApp.jsx
remote:        Module not found: Error: Cannot resolve 'file' or 'directory' /tmp/build_5f0499a33a66627b6911c88bcf69f8ab/client/node_modules/react in /tmp/build_5f0499a33a66627b6911c88bcf69f8ab/client/app/bundles/appbundle/startup

该错误似乎很简单,但我不明白为什么它找不到文件。它在我的本地机器上发现它们非常好,所以我不明白出了什么问题。

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

const devBuild = process.env.NODE_ENV !== 'production'
const nodeEnv = devBuild ? 'development' : 'production'

const config = {
  entry: [
    'es5-shim/es5-shim',
    'es5-shim/es5-sham',
    'babel-polyfill'
  ].concat(glob.sync('./app/bundles/**/startup/*')),

  output: {
    filename: 'webpack-bundle.js',
    path: '../app/assets/webpack'
  },

  resolve: {
    extensions: ['', '.js', '.jsx'],
    alias: {
      react: path.resolve('./node_modules/react'),
      'react-dom': path.resolve('./node_modules/react-dom')
    }
  },

  plugins: [
    new webpack.DefinePlugin({
      'process.env': {
        NODE_ENV: JSON.stringify(nodeEnv)
      }
    })
  ],

  module: {
    loaders: [
      {
        test: require.resolve('react'),
        loader: 'imports?shim=es5-shim/es5-shim&sham=es5-shim/es5-sham'
      },

      {
        test: /\.jsx?$/,
        loader: 'babel-loader',
        exclude: /node_modules/
      }
    ]
  }
}

module.exports = config

if (devBuild) {
  console.log('Webpack dev build for Rails')  // eslint-disable-line no-console
  module.exports.devtool = 'eval-source-map'
} else {
  config.plugins.push(
    new webpack.optimize.DedupePlugin()
  )
  console.log('Webpack production build for Rails')  // eslint-disable-line no-console
}
4

0 回答 0