无效的webpack配置对象

时间:2017-08-13 07:41:52

标签: node.js linux 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? }

问题是什么?我必须做出哪些改变?

1 个答案:

答案 0 :(得分:1)

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

您所要做的就是从解析对象中删除root

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)/
      }
    ]
  }
}