3

i've built a react app in ES6 and created a bundle.js and anchored it in an HTML page served by django. The app worked fine during development running on the node server, but when the page is served by django linking to the static bundle.js file, i got the following error:

VM1517:1 Uncaught Error: Cannot find module "./src/index.js"

note that index.js is the entry point of this react app. any help is appreciated! thanks!

the webpack.config.js is below:

module.exports = {
  entry: [
    './src/index.js'
  ],
  output: {
    path: __dirname,
    publicPath: '/',
    filename: 'bundle.js'
  },
  module: {
    loaders: [{
      exclude: /node_modules/,
      loader: 'babel'
    }]
  },
  resolve: {
    extensions: ['', '.js', '.jsx']
  },
  devServer: {
    contentBase: './'
  }
};

UPDATE: @kaylus the result of running webpack is below:

ERROR in ./src/index.js
Module build failed: SyntaxError: Unexpected token (137:12)

  135 |     render() {
  136 |         return (
> 137 |             <div className='container'>

UPDATE: i solved this issue by following @Kaylus's link to this post https://stackoverflow.com/a/33460642/3974213

Community
  • 1
  • 1
totoro
  • 3,257
  • 5
  • 39
  • 61
  • What is the result of running **webpack**? – LimpingNinja May 08 '17 at 05:26
  • @Kaylus thanks for the reply! please see the updated post. apparently you're right on. why the error? – totoro May 08 '17 at 05:40
  • 1
    I'm assuming it is similar to this entry: [babel-loader jsx SyntaxError](http://stackoverflow.com/questions/33460420/babel-loader-jsx-syntaxerror-unexpected-token?answertab=votes#tab-top). Give that a check first, you may likely need both ES and REACT presets. – LimpingNinja May 08 '17 at 05:50

1 Answers1

1

Make sure you have a .babelrc with at least es2015 and react as presets. Also, and I may be reading this wrong, but if your output filename is "bundle.js", why are you trying to serve "index.js"?

UPDATE:

Nevermind, I did read that wrong. Add a publicPath to your devServer as well.

Clayton Ray
  • 265
  • 2
  • 13