0

When trying to deploy a react_on_rails app to heroku. I get a series of the following errors. Everything works fine locally, however when I try to deploy to heroku I get:

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

The error seems straight forward, but I don't understand why it is not finding the files. It finds them perfectly fine on my local machine, so I don't understand what is wrong.

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
}
Riina
  • 530
  • 1
  • 7
  • 19
  • Hi Riina, did you manage to find a solution to your problem? I'm having the same issue and can't figure out why :( – fabdarice Mar 02 '17 at 20:10
  • Its been quite a while I can't remember the exact solution, but part of the problem was that I was editing the wrong package.json (I had two in my rails project, one in the root directory and one in the react on rails client directory). Also I was installing module and saving modules in the wrong directory. Make sure all the modules you use are also saved in the client/package.json file. – Riina Mar 04 '17 at 07:48

0 Answers0