2017-08-13 117 views
2

我想访问这样无效的WebPack配置对象

var Builder = require('Builder'); 

代替

var Builder = require('./app/components/Builder'); 

模块所以我生成

webpack.config.js

文件使用

的WebPack版本1.12.13

这里是我的文件

module.exports = 
{ 
    entry :'./app/app.jsx', 
    output :{ 
    path : __dirname, 
    filename: './client/bundle.js' 
    }, 
    resolve :{ 
    root : __dirname, 
    alias : { 

    }, 
    extensions : ['.js','.jsx'] 
    }, 
    module :{ 
    loaders : [ 
     { 
      loader :'babel-loader', 
      query :{ 
      presets:['react','es2015'] 
      }, 
      test :/\.jsx?$/, 
      exclude :/(node_modules|bower_components)/ 
     } 
    ] 
    } 
} 

一切都很正常,直到我更新了我的

的WebPack到版本3.5.4

和运行的WebPack我得到这个错误在resolve object

Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema. 
- configuration.resolve has an unknown property 'root'. These properties are valid: 
    object { alias?, aliasFields?, cachePredicate?, cacheWithContext?, descriptionFiles?, enforceExtension?, enforceModuleExtension?, extensions?, fileSystem?, mainFields?, mainFiles?, moduleExtensions?, modules?, plugins?, resolver?, symlinks?, unsafeCache?, useSyncFileSystemCalls? } 

有什么问题和变化做我必须做?

+0

的[我的文件的WebPack设置基本路径]可能的复制(https://stackoverflow.com/questions/45400608/set去除根-base-paths-for-my-files-for-webpack) –

回答

1

resolve.root不是有效的webpack配置属性。 https://webpack.js.org/configuration/resolve/

所有你需要做的是从解决对象

module.exports = 
{ 
    entry :'./app/app.jsx', 
    output :{ 
    path : __dirname, 
    filename: './client/bundle.js' 
    }, 
    resolve :{ 
    alias : { 

    }, 
    extensions : ['.js','.jsx'] 
    }, 
    module :{ 
    loaders : [ 
     { 
      loader :'babel-loader', 
      query :{ 
      presets:['react','es2015'] 
      }, 
      test :/\.jsx?$/, 
      exclude :/(node_modules|bower_components)/ 
     } 
    ] 
    } 
} 
+0

所以我们现在使用path.resolve解析路径? – henrybbosa

+0

Theres几种解决路径的方法。 path.resolve是1种方式,你也可以使用别名。要做什么取决于你在应用程序编译时试图完成什么。 – thomasmeadows

+0

https://webpack.js.org/guides/migrating/#resolve-root-resolve-fallback-resolve-modulesdirectories – thomasmeadows