Antd Pro Beta2 项目在 clone 之后 tyarn start 报错

更新日期: 2021-11-08 阅读次数: 3217 字数: 316 分类: ReactJS

开发时倒是好好的,但是再次 clone 到不同目录,或者其他电脑上 clone 之后,先 tyarn 安装依赖,然后 tyarn start 报错:

> tyarn start
yarn run v1.22.10
$ cross-env UMI_ENV=dev umi dev
Browserslist: caniuse-lite is outdated. Please run:
npx browserslist@latest --update-db

Why you should do it regularly:
https://github.com/browserslist/browserslist#browsers-data-updating
Bundle with webpack 5...
Starting the development server...
Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
 - configuration[0] has an unknown property 'experiments'. These properties are valid:
   object { amd?, bail?, cache?, context?, dependencies?, devServer?, devtool?, entry?, externals?, infrastructureLogging?, loader?, mode?, module?, name?, node?, optimization?, output?, parallelism?, performance?, plugins?, profile?, recordsInputPath?, recordsOutputPath?, recordsPath?, resolve?, resolveLoader?, serve?, stats?, target?, watch?, watchOptions? }
WebpackOptionsValidationError: Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
 - configuration[0] has an unknown property 'experiments'. These properties are valid:
   object { amd?, bail?, cache?, context?, dependencies?, devServer?, devtool?, entry?, externals?, infrastructureLogging?, loader?, mode?, module?, name?, node?, optimization?, output?, parallelism?, performance?, plugins?, profile?, recordsInputPath?, recordsOutputPath?, recordsPath?, resolve?, resolveLoader?, serve?, stats?, target?, watch?, watchOptions? }
    at Object.webpack (/xxx/node_modules/@umijs/deps/compiled/webpack/4/bundle4.js:138983:9)
    at Bundler.setupDevServerOpts (/xxx/node_modules/@umijs/bundler-webpack/lib/index.js:197:40)
    at /xxx/node_modules/umi/node_modules/@umijs/preset-built-in/lib/plugins/commands/dev/dev.js:300:30
    at Generator.next (<anonymous>)
    at asyncGeneratorStep (/xxx/node_modules/umi/node_modules/@umijs/preset-built-in/lib/plugins/commands/dev/dev.js:74:103)
    at _next (/xxx/node_modules/umi/node_modules/@umijs/preset-built-in/lib/plugins/commands/dev/dev.js:76:194)
Done in 7.44s.

这个报错信息简直了,相当于没有。。。

在 Antd Pro Github Issue 中找到一个同样的问题讨论,并给出解决方法:

https://github.com/ant-design/ant-design-pro/issues/8767

是的,我发现报错原因是:config/config.dev.ts中有一个webpack5的空配置项 {},需要将该属性设置为false。

修复方法

修改 config/config.dev.ts

//webpack5: {
//  // lazyCompilation: {},
//},
webpack5: false,

好了,终于可以正常启动了。

微信关注我哦 👍

大象工具微信公众号

我是来自山东烟台的一名开发者,有感兴趣的话题,或者软件开发需求,欢迎加微信 zhongwei 聊聊, 查看更多联系方式

tags: Ant Design Pro