简体   繁体   English

React 不支持 Antd 源 map

[英]Antd source map not supported in React

I have an issue regarding the integration of Ant Design library in a CRA (create-react-app).我有一个关于在 CRA(create-react-app)中集成 Ant 设计库的问题。

After I have tried to integrate it as it is required in their documentation , without integration of Craco, I always get these 4 warnings:在我尝试按照他们的文档的要求集成它之后,没有集成 Craco,我总是收到以下 4 个警告:

WARNING in ./node_modules/antd/dist/antd.css (./node_modules/css-loader/dist/cjs.js??ruleSet[1].rules[1].oneOf[5].use[1]!./node_modules/postcss-loader/dist/cjs.js??ruleSet[1].rules[1].oneOf[5].use[2]!./node_modules/source-map-loader/dist/cjs.js!./node_modules/antd/dist/antd.css)
Module Warning (from ./node_modules/source-map-loader/dist/cjs.js):
Failed to parse source map: 'webpack://antd/./components/config-provider/style/index.less' URL is not supported
 @ ./node_modules/antd/dist/antd.css 8:6-231 22:17-24 26:7-21 58:25-39 59:36-47 59:50-64 61:4-74:5 63:6-73:7 64:54-65 64:68-82 70:42-53 70:56-70 72:21-28 83:0-201 83:0-201 84:22-29 84:33-47 84:50-64
 @ ./src/components/pages/app/App.tsx 10:0-28
 @ ./src/components/index.ts 3:0-34 4:15-18
 @ ./src/index.tsx 6:0-31 8:38-41

WARNING in ./node_modules/antd/dist/antd.css (./node_modules/css-loader/dist/cjs.js??ruleSet[1].rules[1].oneOf[5].use[1]!./node_modules/postcss-loader/dist/cjs.js??ruleSet[1].rules[1].oneOf[5].use[2]!./node_modules/source-map-loader/dist/cjs.js!./node_modules/antd/dist/antd.css)
Module Warning (from ./node_modules/source-map-loader/dist/cjs.js):
Failed to parse source map: 'webpack://antd/./components/icon/style/index.less' URL is not supported
 @ ./node_modules/antd/dist/antd.css 8:6-231 22:17-24 26:7-21 58:25-39 59:36-47 59:50-64 63:6-73:7 64:54-65 64:68-82 70:42-53 70:56-70 72:21-28 83:0-201 83:0-201 84:22-29 84:33-47 84:50-64 61:4-74:5
 @ ./src/components/pages/app/App.tsx 10:0-28
 @ ./src/components/index.ts 3:0-34 4:15-18
 @ ./src/index.tsx 6:0-31 8:38-41

WARNING in ./node_modules/antd/dist/antd.css (./node_modules/css-loader/dist/cjs.js??ruleSet[1].rules[1].oneOf[5].use[1]!./node_modules/postcss-loader/dist/cjs.js??ruleSet[1].rules[1].oneOf[5].use[2]!./node_modules/source-map-loader/dist/cjs.js!./node_modules/antd/dist/antd.css)
Module Warning (from ./node_modules/source-map-loader/dist/cjs.js):
Failed to parse source map: 'webpack://antd/./components/locale-provider/style/index.less' URL is not supported
 @ ./node_modules/antd/dist/antd.css 8:6-231 22:17-24 26:7-21 58:25-39 59:36-47 59:50-64 63:6-73:7 64:54-65 64:68-82 70:42-53 70:56-70 72:21-28 83:0-201 83:0-201 84:22-29 84:33-47 84:50-64 61:4-74:5
 @ ./src/components/pages/app/App.tsx 10:0-28
 @ ./src/components/index.ts 3:0-34 4:15-18
 @ ./src/index.tsx 6:0-31 8:38-41

WARNING in ./node_modules/antd/dist/antd.css (./node_modules/css-loader/dist/cjs.js??ruleSet[1].rules[1].oneOf[5].use[1]!./node_modules/postcss-loader/dist/cjs.js??ruleSet[1].rules[1].oneOf[5].use[2]!./node_modules/source-map-loader/dist/cjs.js!./node_modules/antd/dist/antd.css)
Module Warning (from ./node_modules/source-map-loader/dist/cjs.js):
Failed to parse source map: 'webpack://antd/./components/time-picker/style/index.less' URL is not supported
 @ ./node_modules/antd/dist/antd.css 8:6-231 22:17-24 26:7-21 58:25-39 59:36-47 59:50-64 63:6-73:7 64:54-65 64:68-82 70:42-53 70:56-70 72:21-28 83:0-201 83:0-201 84:22-29 84:33-47 84:50-64 61:4-74:5
 @ ./src/components/pages/app/App.tsx 10:0-28
 @ ./src/components/index.ts 3:0-34 4:15-18
 @ ./src/index.tsx 6:0-31 8:38-41

I use the following versions:我使用以下版本:

"antd": "^4.19.2",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-router-dom": "^5.1.2",
"react-scripts": "5.0.0",

Can someone help me regarding this issue?有人可以帮我解决这个问题吗? Thank you!谢谢!

This problem occurred after react-script was upgraded to 5.0.0 solution : react-script 升级到 5.0.0 后出现这个问题的解决方法:

- import 'antd/dist/antd.css

replace with :用。。。来代替 :

+ import 'antd/dist/antd.min.css

Though, I succeeded in eliminating the errors only by integrating CRACO and LESS.不过,我只是通过集成 CRACO 和 LESS 成功地消除了错误。 Changing in src/App.tsx :更改src/App.tsx

- import '~antd/dist/antd.css';
+ import '~antd/dist/antd.less';

So, from what I see, the issue may be with the import '~antd/dist/antd.css';所以,据我所见,问题可能出在import '~antd/dist/antd.css'; , imported in src/App.tsx . , 在src/App.tsx中导入。

The previous solution did not work for me, because although it was removing the compilation error it was breaking all the Antd styles of the app.之前的解决方案对我不起作用,因为虽然它消除了编译错误,但它破坏了应用程序的所有 Antd 样式。

We found this solution instead:我们找到了这个解决方案:

import 'antd/dist/antd.min.css'导入“antd/dist/antd.min.css”

From this Chinese site .来自这个中文网站

A more customized solution would be to use customize-cra一个更定制化的解决方案是使用custom-cra

Actually it is also solved in the issues of their repo!实际上它在他们的回购问题中也得到了解决!

after spending much time on fixing this,, i found that adding GENERATE_SOURCEMAP=false to your .env file will remove the error.在花了很多时间解决这个问题后,我发现将GENERATE_SOURCEMAP=false添加到您的 .env 文件将消除错误。

it is said that this is caused by Webpack 5.据说这是由 Webpack 5 引起的。

in app.tsx use import "antd/dist/antd.min.css";在 app.tsx 中使用 import "antd/dist/antd.min.css"; to replace import "antd/dist/antd.css";替换导入“antd/dist/antd.css”;

If you're experiencing this issue with react-scripts/cra version 5.0.0.如果您在使用 react-scripts/cra 版本 5.0.0 时遇到此问题。 You'll need to add the following to your.env file您需要将以下内容添加到 your.env 文件中

GENERATE_SOURCEMAP=false GENERATE_SOURCEMAP=false

or you can update your script to或者您可以将脚本更新为

"start": "GENERATE_SOURCEMAP=false react-scripts start", Note: this is a temporary patch until 5.0.1 is released. "start": "GENERATE_SOURCEMAP=false react-scripts start", 注意:这是一个临时补丁,直到 5.0.1 发布。 See create-react-app repo pull request Update: 5.0.1 was release on April 2022. Changelog.请参阅 create-react-app repo pull request 更新:5.0.1 于 2022 年 4 月发布。变更日志。 The update did not fix this issue.更新没有解决这个问题。 Not sure when that will be ♂️不知道什么时候会♂️

By: roger-perez作者:罗杰-佩雷斯

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

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