node.js - Configuration.resolve 有一个未知属性 'root'

标签 node.js webpack bundle config

我收到以下错误:

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?, descriptionFiles?, enforceExtension?, enforceModuleExtension?, extensions?, fileSystem?, mainFields?, mainFiles?, moduleExtensions?, modules?, plugins?, resolver?, symlinks?, unsafeCache?, useSyncFileSystemCalls? }

我使用 webpack 2.3.2 .


我的 webpack.config.js 看起来像这样:

module.exports= {
  entry:'./public/app.jsx',
  output: {
    path: __dirname,
    filename:'./public/bundle.js'
  },
  resolve: {
    root: __dirname,
    alias:{
      Mod1: 'public/components/mod1.jsx',
      Mod2:'public/components/mod2.jsx',
      Mod3: 'public/components/mod3.jsx'
    },
    extensions: ['*','.js','.jsx']
  },
  module :{
    loaders:[{
      loader :'babel-loader',
      query :{
        presets:['react','es2015','es2017']
      },
      test:/\.jsx?$/,
      exclude:/(node_modules|bower_components)/
    }]
  }
};

最佳答案

resolve.root 是 Webpack 1 的配置,在 Webpack 2 中不存在。

对于 Webpack 2,您可以使用 resolve.modules:https://webpack.js.org/configuration/resolve/#resolve-modules

module.exports= {
  entry:'./public/app.jsx',
  output: {
    path: __dirname,
    filename:'./public/bundle.js'
  },
  resolve: {
    modules: [__dirname, 'node_modules'],
    alias:{
      Mod1: 'public/components/mod1.jsx',
      Mod2:'public/components/mod2.jsx',
      Mod3: 'public/components/mod3.jsx'
    },
    extensions: ['*','.js','.jsx']
  },
  module :{
    rules:[{
      use : 'babel-loader',
      query :{
        presets:['react','es2015','es2017']
      },
      test: /\.jsx?$/,
      exclude: /(node_modules|bower_components)/
    }]
  }
};

我还更新了 module.loaders -> module.rules 因为这在 Webpack 2 中已被弃用。

关于node.js - Configuration.resolve 有一个未知属性 'root',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43107233/

相关文章:

node.js - 从 API 获取 POST 数据(node js、react)

javascript - ReactJS-图像src调用另一个文件夹错误

javascript - 在 Mocha 测试期间需要/导入 svg

ios - XCode 4.5.2 : How to reconcile "Failed to attach to process ID 0" with the need for a Resources folder?

node.js - 使用 node.js 直接从服务器使用 youtube/google API 上传视频?

javascript - 我该如何处理错误,忽略它并继续使用该功能?不和谐.js

java - 在项目 xxx 的构建路径中检测到循环 - 构建路径问题

android - Activity 没有得到正确的包

javascript - 为什么 spread() 方法在 Sequelize 中不起作用?

javascript - Async React.Component 对我不起作用