在 react react-leaflet 中编译失败
Posted
技术标签:
【中文标题】在 react react-leaflet 中编译失败【英文标题】:Failed to compile in react react-leaflet 【发布时间】:2021-03-27 20:37:57 【问题描述】:我尝试使用当前版本的 react、react-leaflet 和 Leaflet 制作项目,但出现此错误:
编译失败。
./src/components/ViewMap.js 未找到模块:无法解析 'C:\Users...\src\components'中的'react-leafet'
我的 Package.json:
"name": "leaflet_react_gms02",
"version": "0.1.0",
"private": true,
"dependencies":
"@testing-library/jest-dom": "^5.11.6",
"@testing-library/react": "^11.2.2",
"@testing-library/user-event": "^12.6.0",
"leaflet": "^1.7.1",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-leaflet": "^3.0.4",
"react-scripts": "4.0.1",
"web-vitals": "^0.2.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":
【问题讨论】:
【参考方案1】:几周前我遇到了同样的问题。这个解决方案对我有用 -
从你的项目中删除node module
和package-lock.json
,然后运行npm install
。
在评论中告诉我它是否适合你。
【讨论】:
它对我不起作用。我有相同的包,我已经按照react-leaflet.js.org/docs/start-installation上的指南一步一步地进行操作以上是关于在 react react-leaflet 中编译失败的主要内容,如果未能解决你的问题,请参考以下文章
使用 react-leaflet 在标记内实现动态 JSX 元素