简体   繁体   English

Webpack配置有一个未知属性'preLoaders'

[英]Webpack config has an unknown property 'preLoaders'

I'm learning webpack from scratch. 我正在从头开始学习webpack。 I've learned how to link javascript files with require. 我已经学会了如何将javascript文件与require链接起来。 I'm bundling and minifying my js files and i'm listening for changes with watch. 我正在捆绑和缩小我的js文件,我正在监听手表的变化。 I'm setting up loaders to convert my sass files to css. 我正在设置加载器将我的sass文件转换为css。 But when I try to setup a linting process with jshint-loader, i'm running into issues. 但是当我尝试使用jshint-loader设置linting过程时,我遇到了问题。

    module: {
preLoaders: [
        {
            test: /\.js$/, // include .js files
            exclude: /node_modules/, // exclude any and all files in the node_modules folder
            loader: "jshint-loader"
        }
],

loaders: [
  {
    test: /\.scss$/,
    loader: 'style-loader!css-loader!sass-loader'
  },
  {
    test: /\.js$/,
    loader: 'babel-loader',
    exclude: /node_modules$/,
    query: {
      presets: ['es2015']
    }
  }
],

} }

Here is the error 这是错误

Invalid configuration object. 配置对象无效。 Webpack has been initialised using a configuration object that does not match the API schema. Webpack已使用与API架构不匹配的配置对象进行初始化。 - configuration.module has an unknown property 'preLoaders'. - configuration.module有一个未知属性'preLoaders'。 These properties are valid: object { exprContextCritical?, exprContextRecursive?, exprContextRegExp?, exprContextRequest?, loaders?, noParse?, rules?, unknownContextCritical?, unknownContextRecursive?, unknownContextRegExp?, unknownContextRequest?, unsafeCache?, wrappedContextCritical?, wrappedContextRecursive?, wrappedContextRegExp? 这些属性是有效的:object {exprContextCritical?,exprContextRecursive?,exprContextRegExp?,exprContextRequest?,loaders?,noParse ?, rules ?, unknownContextCritical?,unknownContextRecursive?,unknownContextRegExp?,unknownContextRequest?,unsafeCache?,wrappedContextCritical?,wrappedContextRecursive?,wrappedContextRegExp ? } Options affecting the normal modules ( NormalModuleFactory ). 影响正常模块的选项( NormalModuleFactory )。

You are apparently trying to use examples for webpack v1 with webpack v2. 您显然正在尝试使用webpack v1和webpack v2的示例。 Straight from the changelog : 直接来自更改日志

  module: {
-   preLoaders: [
+   rules: [
      {
        test: /\.js$/,
+       enforce: "pre",
        loader: "eslint-loader"
      }
    ]
  }

From v2.1-beta.23 the loaders section is renamed to rules and pre/postLoaders is now defined under each rule with the enforce property. v2.1-beta.23开始 ,加载器部分被重命名为规则,现在在每个规则下使用enforce属性定义pre / postLoaders。

So just rename preLoaders to rules and you should be good to go ;-) 所以只需将preLoaders重命名为rules ,你应该好好去;-)

First uninstall webpack 首先卸载webpack

npm uninstall webpack --save-dev

followed by 其次是

npm install webpack@2.1.0-beta.22 --save-dev

if you are using webpack 2 then you may use the enforce: 'pre' tag inside the loaders array and this will work as a preload please refer code below for details 如果您正在使用webpack 2,那么您可以在加载器数组中使用enforce:'pre'标签,这将作为预加载,请参阅下面的代码了解详细信息

module: {
    loaders: [
        {
            test: /\.js$/,
            exclude: /node_modules/,
            loader: 'jshint-loader',
            //this is similar to defining a preloader
            enforce: 'pre'
        },
        {
            test: /\.es6$/,
            exclude: /node_modules/,
            loader: "babel-loader"
        }
    ]

},

use this one instead ./webpack.config.js 请使用此代码./webpack.config.js

 var path = require('path');

module.exports = {
   entry: './main.ts',
   resolve: {
     extensions: ['.webpack.js', '.web.js', '.ts', '.js']
   },
   module: {
     rules: [
      {
        test: /\.tsx?$/,
        use: 'ts-loader',
        exclude: /node_modules/
      }
    ]
   },
   output: {
     filename: 'bundle.js',
     path: path.resolve(__dirname, 'dist')
   }
 }

the documentation can be found here the problem is related to the version of ts-loader you installed 这里可以找到文档,问题与您安装的ts-loader版本有关

对我来说,只需将“装载机”改为“规则”即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 webpack.config 有一个未知的属性“publicPath” - webpack.config has an unknown property 'publicPath' Webpack@5.66.0 Webpack 开发服务器配置:选项具有未知属性“统计” - Webpack@5.66.0 Webpack dev server config: options has an unknown property 'stats' WebPack 2:迁移preLoaders和postLoaders - WebPack 2: Migrate preLoaders and postLoaders Webpack错误:配置具有未知属性'postcss' - Webpack error: configuration has an unknown property 'postcss' 将 webpack 4 更新到 webpack 5 get error options has an unknown property 'inline' - Update webpack 4 to webpack 5 get error options has an unknown property 'inline' Webpack:未知参数:模式/配置具有未知属性“模式” - Webpack: Unknown argument: mode / configuration has an unknown property 'mode' Webpack 错误:configuration.module.rules[0] 有一个未知属性 'query' - Webpack error: configuration.module.rules[0] has an unknown property 'query' webpack 4.1.1 - > configuration.module有一个未知的属性'loaders'。 - webpack 4.1.1 -> configuration.module has an unknown property 'loaders'. Webpack 错误 - configuration.node 具有未知属性“fs” - Webpack Error - configuration.node has an unknown property 'fs' webpack-dev-server 返回“配置有一个未知的属性‘错误’” - webpack-dev-server return “configuration has an unknown property 'error'”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM