[英]Can't get antd to work with create-react-app
我想嘗試將 ant.design 與 create-react-app 一起使用,所以我按照 antd 文檔中給出的步驟進行操作。
https://ant.design/docs/react/use-with-create-react-app
npx create-react-app antd-demo
npm add antd
在 app.js 文件中,
import React from 'react';
import { Button } from 'antd';
import './App.css';
const App = () => (
<div className="App">
<Button type="primary">Button</Button>
</div>
);
export default App;
並在 App.css
@import '~antd/dist/antd.css';
.App {
text-align: center;
}
...
當我啟動它時,我得到了這個錯誤
錯誤:找不到模塊“./locale”
▶ 2 個堆棧框架被折疊。
https://imgur.com/a/0Yc4AdM (錯誤截圖)
所以我用谷歌搜索了它,我發現它與我也安裝的 moment.js 有關,但我仍然繼續遇到同樣的錯誤。
您可以嘗試特定版本的Moment
以按照步驟操作。 Moment 版本 2.25.1 將不起作用。 如何使用 npm 強制 2.24.0 版本,而不是紗線和分辨率塊?
簡單的技巧: -
npm install --save-dev npm-force-resolutions
add in package.json
"resolutions": {
"moment": "2.24.0"
}
添加到 package.json 中的“腳本”節點
"preinstall": "npx npm-force-resolutions"
型號 npm 安裝
希望這可以幫助。 有關詳細信息,請關注 Antd 團隊中記錄的錯誤 ( https://github.com/ant-design/ant-design-pro/issues/6512 )。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.