2016-09-23 74 views
1

我有一個奇怪的問題,我似乎無法解決。Webpack2無法解析路徑名中的文件

我收到此錯誤:

Error: Can't resolve 'store/configureStore' in '/Users/samboy/company/oh-frontend/app' 

我的WebPack文件看起來像這樣:

name: 'browser', 
    context: path.join(__dirname, '..', '..', '..', 'app'), 
    entry: { 
     app: './client' 
    }, 
    output: { 
     // The output directory as absolute path 
     path: assetsPath, 
     // The filename of the entry chunk as relative path inside the output.path directory 
     filename: '[name].js', 
     // The output path from the view of the Javascript 
     publicPath: publicPath 

    }, 

    module: { 
     loaders: commonLoaders 
    }, 
    resolve: { 
     modules: [ 
     path.resolve(__dirname, '..', '..', '..', 'app'), 
     'node_modules' 
     ], 
     extensions: ['', '.js', '.jsx', '.css'] 
    }, 
    plugins: [ 
     // extract inline css from modules into separate files 
     new ExtractTextPlugin('styles/bundled-modules.css'), 
     // files in global directory should be concatenated into one file for prod 
     new CopyWebpackPlugin([ 
      { from: 'fonts/', to: 'fonts/' } 
      , { from: '_web/css/global/fonts.css', to: 'styles/fonts.css' } 
      , { from: '_web/css/vendors', to: 'styles/vendors' } 
     ]), 
     new webpack.optimize.UglifyJsPlugin({ 
      compressor: { 
      warnings: false 
      } 
     }), 
     new webpack.DefinePlugin({ 
      __DEVCLIENT__: false, 
      __DEVSERVER__: false, 
      __PLATFORM_WEB__: true, 
      __PLATFORM_IOS__: false 
     }), 
     new InlineEnviromentVariablesPlugin({ NODE_ENV: 'production' }),function() 
    { 
     this.plugin("done", function(stats) 
     { 
      if (stats.compilation.errors && stats.compilation.errors.length) 
      { 
       console.log(stats.compilation.errors); 
       process.exit(1); 
      } 
      // ... 
     }); 
    } 
    ], 
    postcss: postCSSConfig 
    } 

的文件肯定是存在該文件夾中。它在webpack上運行良好。它似乎並沒有與webpack2工作。

回答

0

我在猜測,因爲您沒有發佈您的應用程序文件,但是您能否將應用程序文件中的導入語句更改爲「./store/configureStore」?

+0

我想你是對的。我添加了它,並開始在其他地方發生錯誤。這樣說,有沒有辦法讓我不必添加'./'?這將使我修改1000個文件。它似乎與webpack一起工作正常,但只有webpack2 – ahskaus

+0

./意味着它是一個相對路徑而不是別名。想象一下,例如,「jquery」和「./jquery」之間的混淆。你最好的選擇是在IDE中使用查找和替換工具 – eavidan