2017-07-22 109 views
0

我安装一个反应startUpapp和添加的WebPack但它说Can't resolve './src/index.js'录入模块未找到:错误:无法解析” ./src/index.js'

浏览器显示
My App give this look

我的文件路径和Package.josn它 enter image description here

webpack.config.js Files Look:

var debug = process.env.NODE_ENV !== "production"; 
    var webpack = require('webpack'); 
    var path = require('path'); 

    module.exports = { 
     context: path.join(__dirname, "public"), 
    devtool: debug ? "inline-sourcemap" : false, 
    entry: "./src/index.js", 
    module: { 
     loaders: [ 
      { 
       test: /\.jsx?$/, 
       exclude: /(node_modules|bower_components)/, 
       loader: 'babel-loader', 
       query: { 
        presets: ['react', 'es2016', 'stage-0'], 
        plugins: ['react-html-attrs', 'transform-decorators-legacy', 'transform-class-properties'], 
       } 
      } 
     ] 
    }, 
    output: { 
     path: __dirname + "/public/", 
     filename: "build.js" 
    }, 
    plugins: debug ? [] : [ 
     new webpack.optimize.DedupePlugin(), 
     new webpack.optimize.OccurrenceOrderPlugin(), 
     new webpack.optimize.UglifyJsPlugin({ mangle: false, sourcemap: false }), 
    ], 
}; 

回答

3

您的基本网址path.join(__dirname, "public")和条目./src/index.js。 Webpack尝试在public dir中找到./src/index.js,显然它不存在。您应修改entry../src/index.js

+0

感谢@kermit错误在./src/index.js中 模块构建失败:错误:无法找到与目录“C:\\ Users \\ ashik \”相关的预设“es2016” \ Desktop“' 但我得到新的错误 –

+0

谢谢我解决它通过添加'.babelrc'文件 –

0

输入路径是相对于上下文的。当你想在/src中寻找路径时,它正在寻找public/src/中的文件。看看你的webpack.config.js的其余部分,看起来你并不需要上下文线。

https://webpack.js.org/configuration/entry-context/

相关问题