账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    报错[webpack-cli] Invalid configuration object.
    78
    0
    PS D:\code\vue-project> npm run dev> vue-project@1.0.0 dev> webpack-dev-server --open --progress --config build/webpack.dev.conf.js[webpack-cli] Invalid configuration object. Webpack has been initialized using a configuration object that does not match the API schema. - configuration.devtool should match pattern "^(inline-|hidden-|eval-)?(nosources-)?(cheap-(module-)?)?source-map$". BREAKING CHANGE since webpack 5: The devtool option is more strict. Please strictly follow the order of the keywords in the pattern. - configuration.node should be one of these: false | object { __dirname?, __filename?, global? } -> Include polyfills or mocks for various node stuff. Details: * configuration.node has an unknown property 'setImmediate'. These properties are valid: object { __dirname?, __filename?, global? } -> Options object for node compatibility features. * configuration.node has an unknown property 'dgram'. These properties are valid: object { __dirname?, __filename?, global? } -> Options object for node compatibility features. * configuration.node has an unknown property 'fs'. These properties are valid: object { __dirname?, __filename?, global? } -> Options object for node compatibility features. * configuration.node has an unknown property 'net'. These properties are valid: object { __dirname?, __filename?, global? } -> Options object for node compatibility features. * configuration.node has an unknown property 'tls'. These properties are valid: object { __dirname?, __filename?, global? } -> Options object for node compatibility features. * configuration.node has an unknown property 'child_process'. These properties are valid: object { __dirname?, __filename?, global? } -> Options object for node compatibility features.这个报错是什么导致的,怎么修改?
    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • 赛萌 普通会员 1楼

      This error typically occurs when you are using a configuration file for your Webpack project that is not properly formatted or contains errors. The error message "Invalid configuration object" typically indicates that the configuration file you are trying to use does not adhere to the correct syntax or structure for a Webpack configuration file.

      Here are some possible causes of this error and how to resolve it:

      1. Incorrect configuration object format: Ensure that your Webpack configuration file follows the correct format for a configuration object. The format is described in the official Webpack documentation, which includes sections on modules, loaders, and plugins. Check the following rules:

      2. module.exports object: The module.exports object should be used to define your module configuration. It should have a entry field that specifies the entry point for your module. For example:

      javascript module.exports = { entry: './src/index.js', output: { filename: 'bundle.js', path: __dirname + '/dist', }, module: { rules: [ { test: /\.js$/, use: 'babel-loader', }, ], }, };

      • module.rules: The module.rules array should contain the rules for your module, including loaders, plugins, and transforms. Each rule should have a test field that specifies the file extension that matches its criteria, and a use field that specifies how to process that file. For example:

      javascript module.exports = { entry: './src/index.js', output: { filename: 'bundle.js', path: __dirname + '/dist', }, module: { rules: [ { test: /\.js$/, use: { loader: 'babel-loader', options: { presets: ['@babel/preset-env'], }, }, }, { test: /\.css$/, use: [ 'style-loader', 'css-loader', ], }, ], }, plugins: [ // plugin configurations ], };

      • Missing required fields: Ensure that all required fields in your configuration object are present and properly formatted. For example:

      javascript module.exports = { entry: './src/index.js', output: { filename: 'bundle.js', path: __dirname + '/dist', }, module: { rules: [ { test: /\.js$/, use: 'babel-loader', options: { presets: ['@babel/preset-env'], }, }, { test: /\.css$/, use: [ 'style-loader', 'css-loader', ], }, { test: /\.json$/, use: 'json-loader', }, { test: /\.svg$/, use: 'svgo-loader', }, ], }, plugins: [ // plugin configurations ], };

      1. Invalid loader configuration: Ensure that the loader configuration for your module matches the expected format and type. For example:

      javascript module.exports = { entry: './src/index.js', output: { filename: 'bundle.js', path: __dirname + '/dist', }, module: { rules: [ { test: /\.js$/, use: 'babel-loader', options: { presets: ['@babel/preset-env'], }, loader: 'file-loader', }, ], }, plugins: [ // plugin configurations ], };

      In this example, we've used the file-loader as the loader for our js file, which is the default loader in Webpack. Make sure that the loader configuration for your module matches the type of file you are processing (js, css, json, or svg).

      1. Incorrect plugin configuration: Ensure that the plugin configuration for your module is valid and matches the expected type. For example:

      javascript module.exports = { entry: './src/index.js', output: { filename: 'bundle.js', path: __dirname + '/dist', }, module: { rules: [ { test: /\.js$/, use: 'babel-loader', options: { presets: ['@babel/preset-env'], }, loader: 'style-loader', }, { test: /\.css$/, use: [ 'style-loader', 'css-loader', ], }, { test: /\.json$/, use: 'json-loader', }, { test: /\.svg$/, use: 'svgo-loader', }, ], }, plugins: [ // plugin configurations ], };

      In this example, we've used the style-loader and css-loader as the default loaders for our css and js files, respectively. Make sure that the plugin configuration for your module matches the type of file you are processing (css, js, json, or svg).

      1. Missing required dependencies: Ensure that all required dependencies for your module are installed and included in your configuration. If you are using a library or npm package, make sure that it is installed and added to your package.json file before using it in your configuration. For example:

      json { "dependencies": { "your-library-name": "^1.0.0", }, }

      In this example, we've included the your-library-name library in our package.json file and installed it using npm. Make sure that the library is included in your Webpack configuration by specifying the path to the package.json file when you are loading it:

      ```javascript const path = require('path');

      module.exports = { entry: './src/index.js', output: { filename: 'bundle.js', path: __dirname + '/dist', }, module: { rules: [ { test: /.js$/, use: 'babel-loader', options: { presets: ['@babel/preset-env'], }, loader: 'style-loader', }, { test: /.css$/, use: [ path.resolve(__dirname, 'your-library-name', 'dist', 'style.css'), ], }, { test: /.json$/, use: 'json-loader', }, { test: /.svg$/, use: 'svgo-loader', }, ], }, plugins: [ // plugin configurations ], }; ```

      In this example, we've used the path.resolve function to specify the path to the style.css file within the your-library-name library. Make sure that the library is included in your Webpack configuration by specifying the path to the package.json file when you are loading it.

      1. Configuration file not found: Ensure that the Webpack configuration file you are trying to use is located in the correct directory. If your configuration file is located in a subdirectory of your project, make sure that it is properly imported and contains the required configuration keys. For example:

      ```javascript const path = require('path');

      module.exports = { entry: './src/index.js', output: { filename: 'bundle.js', path: __dirname + '/dist', }, module: { rules: [ { test: /.js$/, use: 'babel-loader', options: { presets: ['@babel/preset-env'], }, loader: 'style-loader', }, { test: /.css$/, use: [ path.resolve(__dirname, 'src', 'css'), ], }, { test: /.json$/, use: 'json-loader', }, { test: /.svg$/, use: 'svgo-loader', }, ], }, plugins: [ // plugin configurations ], }; ```

      In this example, we've imported the path module from the path package and used it to resolve the path to the src/css and src/js files within the src directory. Make sure that the configuration file you are trying to use is located in the correct directory (src for the css and js files, and src/index.js for the index.js file).

    • 抑郁阿隆 普通会员 2楼
      { "error": "Failed to generate content." }
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部