gpt4 book ai didi

reactjs - Uncaught Error : Cannot find module '@fortawesome/free-regular-svg-icons'

转载 作者:行者123 更新时间:2023-12-05 03:21:38 24 4
gpt4 key购买 nike

我正在尝试将 ReactJS 与 font-awesome 一起使用,但我收到一个模块未找到错误。这些文件位于 npm 模块文件夹中,所以我不确定出了什么问题。

我的 package.json 中有以下内容:

{
"name": "partner-portal",
"version": "0.1.0",
"private": true,
"dependencies": {
"@fortawesome/fontawesome-svg-core": "^6.1.1",
"@fortawesome/free-solid-svg-icons": "^6.1.1",
"@fortawesome/react-fontawesome": "^0.2.0",
"@testing-library/jest-dom": "^5.16.4",
"@testing-library/react": "^13.3.0",
"@testing-library/user-event": "^13.5.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router": "^6.3.0",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"autoprefixer": "^10.4.7",
"postcss": "^8.4.14",
"tailwindcss": "^3.1.4"
}
}

我已经运行了以下命令,库已添加到我的 npm_modules 文件夹中:

yarn add @fortawesome/fontawesome-svg-core
npm i --save @fortawesome/free-solid-svg-icons
npm i --save @fortawesome/free-regular-svg-icons
yarn add @fortawesome/react-fontawesome@latest
npm i --save @fortawesome/free-solid-svg-icons
npm i --save @fortawesome/free-regular-svg-icons

但是当我这样包含它时:

import { faBell } from "@fortawesome/free-regular-svg-icons"

function Form() {

return(
<div className='container w-[1000px] p-5 mx-auto border rounded-2xl'>
<div className='flex flex-wrap'>
<label className="mr-5">Name</label>
</div>

<div className='flex flex-row w-full justify-end'>
<button className="pointer-events-auto ml-8 rounded-md bg-indigo-600 py-2 px-3 text-[0.8125rem] font-semibold leading-5 text-white hover:bg-indigo-500">
<FontAwesomeIcon icon={faBell} />
Save
</button>
</div>

</div>
)
}

export default Form;

我收到以下错误:

Uncaught Error: Cannot find module '@fortawesome/free-regular-svg-icons'
webpackMissingModule bundle.js:214
js bundle.js:214
factory react refresh:6
Webpack 11**

谁能告诉我我做错了什么?

编辑:

我现在继续前进,我正在尝试使用 ReactRouter,我使用以下命令安装了它 npm i react-router。正如您从我更新的 package.json(上图)中看到的那样,我在那里有 react-dom、react-router、react-router-config、react-router-dom。我运行 npm install 没有遇到任何问题。但是当我尝试时:

import {
BrowserRouter as Router,
Switch,
Route,
} from "react-router"

我仍然得到同样的错误。 Uncaught Error: Cannot find module 'react-router' 同样,这些文件位于 node_modules 文件夹中。我做错了什么??!

最佳答案

npm i --save @fortawesome/fontawesome-svg-core
npm install --save @fortawesome/free-solid-svg-icons
npm install --save @fortawesome/react-fontawesome

我有一个类似的问题并通过运行上述命令解决了它,然后我停止了脚本并执行了 npm start 并修复了错误。我希望这会有所帮助。

关于reactjs - Uncaught Error : Cannot find module '@fortawesome/free-regular-svg-icons' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72910017/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com