2016-09-23 75 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