2017-07-22 153 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/

相關問題