django服务ES 6应用程序时,找不到index.js

我已经在ES6中构build了一个反应应用程序,并创build了一个bundle.js并将其锚定在由django提供的HTML页面中。 应用程序在节点服务器上运行的开发过程中工作正常,但是当页面由django链接到静态bundle.js文件时,出现以下错误:

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

请注意, index.js是此反应应用程序的入口点。 任何帮助表示赞赏! 谢谢!

webpack.config.js如下:

 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: './' } }; 

更新:@kaylus运行webpack的结果如下:

 ERROR in ./src/index.js Module build failed: SyntaxError: Unexpected token (137:12) 135 | render() { 136 | return ( > 137 | <div className='container'> 

更新:我通过@ Kaylus的链接到这个post解决了这个问题https://stackoverflow.com/a/33460642/3974213

确保你的.babelrc至less有es2015,并作为预置作出反应。 另外,我可能会读这个错误,但如果你的输出文件名是“bundle.js”,你为什么要服务“index.js”?

更新:

没关系,我的确看错了。 添加一个公共path到你的devServer。