【发布时间】:2022-11-03 05:08:17
【问题描述】:
我正在尝试将 ReactJS 与 font-awesome 一起使用,但我收到了一个找不到模块的错误。这些文件位于 npm modules 文件夹中,所以我不确定出了什么问题。
我的 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 文件夹中。我究竟做错了什么??!
【问题讨论】:
-
您能否添加指向 repo 的链接?
标签: reactjs font-awesome