简体   繁体   English

MUI 和 Next.JS 的 Webpack 问题

[英]Webpack issue with MUI and Next.JS

I'm copying the instructions from this file here:我在此处复制此文件中的说明:

https://github.com/mui-org/material-ui/blob/master/examples/nextjs-with-styled-components-typescript/next.config.js https://github.com/mui-org/material-ui/blob/master/examples/nextjs-with-styled-components-typescript/next.config.js

I get this error when I add the next.config.js code below.当我在下面添加next.config.js代码时出现此错误。

WebpackOptionsValidationError: Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
 - configuration[0].module.rules[1].oneOf[5].include should be one of these:
   RegExp | string | function | [(recursive)] | object { and?, exclude?, include?, not?, or?, test? } | [RegExp | string | function | [(recursive)] | object { and?, exclude?, include?, not?, or?, test? }]
   -> One or multiple rule conditions
   Details:
    * configuration[0].module.rules[1].oneOf[5].include.or[2] should be an instance of RegExp
    * configuration[0].module.rules[1].oneOf[5].include.or[2] should be a string.
    * configuration[0].module.rules[1].oneOf[5].include.or[2] should be an instance of function
    * configuration[0].module.rules[1].oneOf[5].include.or[2] should be an array:
      [RegExp | string | function | [(recursive)] | object { and?, exclude?, include?, not?, or?, test? }]
    * configuration[0].module.rules[1].oneOf[5].include.or[2] should be an object.
    * configuration[0].module.rules[1].oneOf[5].include.or[2] should be one of these:
      RegExp | string | function | [(recursive)] | object { and?, exclude?, include?, not?, or?, test? }
    * configuration[0].module.rules[1].oneOf[5].include.or[2] should be one of these:
      RegExp | string | function | [(recursive)] | object { and?, exclude?, include?, not?, or?, test? }
      -> A rule condition
 - configuration[1].module.rules[1].oneOf[3].issuer should be one of these:
   RegExp | string | function | [(recursive)] | object { and?, exclude?, include?, not?, or?, test? } | [RegExp | string | function | [(recursive)] | object { and?, exclude?, include?, not?, or?, test? }]
   -> One or multiple rule conditions
   Details:
    * configuration[1].module.rules[1].oneOf[2].issuer.or should be an array:
      [RegExp | string | function | [(recursive)] | object { and?, exclude?, include?, not?, or?, test? }]
    * configuration[1].module.rules[1].oneOf[2].issuer.or should be one of these:
      [RegExp | string | function | [(recursive)] | object { and?, exclude?, include?, not?, or?, test? }]
      -> Logical OR
    * configuration[1].module.rules[1].oneOf[3].issuer.or should be an array:
      [RegExp | string | function | [(recursive)] | object { and?, exclude?, include?, not?, or?, test? }]
    * configuration[1].module.rules[1].oneOf[3].issuer.or should be one of these:
      [RegExp | string | function | [(recursive)] | object { and?, exclude?, include?, not?, or?, test? }]
      -> Logical OR
    at webpack (/Users/thomasreggi/Desktop/project-template/node_modules/next/node_modules/webpack/lib/webpack.js:31:9)
    at HotReloader.start (/Users/thomasreggi/Desktop/project-template/node_modules/next/dist/server/hot-reloader.js:14:1858)
    at async DevServer.prepare (/Users/thomasreggi/Desktop/project-template/node_modules/next/dist/server/next-dev-server.js:10:1565)
    at async /Users/thomasreggi/Desktop/project-template/node_modules/next/dist/cli/next-dev.js:21:359
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
const withTM = require('next-transpile-modules')(['@mui/material', '@mui/system']); // pass the modules you would like to see transpiled

module.exports = withTM({
  reactStrictMode: true,
  webpack: (config) => {
    config.resolve.alias = {
      ...config.resolve.alias,
      '@mui/styled-engine': '@mui/styled-engine-sc',
    };
    return config;
  },
});

This was happening because I was using next@9 an older version, fixed by:发生这种情况是因为我使用的是 next@9 旧版本,由以下方式修复:

yarn add next@latest

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM