在我现有的应用程序中,我在本地安装了google-map-react库,我可以看到它列在我的package.json中的dependencies下&这个文件夹也存在于node_modules文件夹中。但是,当我在如下所示的文件中引用组件构造函数时:
从google-map-react导入GoogleMapReact;
但是,当我运行代码时,我得到以下错误:
Error: Cannot find module 'google-map-react'
./src/components/partials/Test.jsx Module not found: Can't resolve 'google-map-react' in '/usr/local/bab/src/components/partials'
我注意到第二个错误中引用的路径不正确。当我的应用程序在~/www/...中时,它指的是/usr/local
我不清楚我做错了什么。该库不是全局安装的,为了以防万一,我运行了npm uninstall -g google-map-react,但是,它也没有帮助。
System: Ubuntu 18.04
Node: v10.15.3
NPM: 6.4.1我的package.json文件:
{
"name": "my-app",
"version": "0.1.0",
"private": true,
"dependencies": {
"@babel/polyfill": "^7.2.5",
"@babel/runtime": "^7.2.0",
"axios": "^0.18.0",
"google-map-react": "^1.1.4",
"moment": "^2.23.0",
"node-sass": "^4.11.0",
"prop-types": "^15.6.2",
"qs": "^6.6.0",
"react": "^16.8.2",
"react-compound-slider": "^0.16.3",
"react-cookie-consent": "^2.1.0",
"react-dates": "^18.3.1",
"react-dom": "^16.8.2",
"react-gtm-module": "^2.0.4",
"react-moment-proptypes": "^1.6.0",
"react-redux": "^6.0.1",
"react-router-dom": "^4.3.1",
"react-scripts": "^2.1.5",
"react-scroll": "^1.7.10",
"react-slick": "^0.23.2",
"react-sticky": "^6.0.3",
"react-transition-group": "^2.5.2",
"redux": "^4.0.1",
"redux-logger": "^3.0.6",
"redux-persist": "^5.10.0",
"redux-thunk": "^2.3.0",
"reselect": "^4.0.0",
"slick-carousel": "^1.8.1"
},
"scripts": {
"lint": "./node_modules/.bin/eslint -c .eslintrc.js 'src/**/*.{js,jsx}'",
"lint:fix": "./node_modules/.bin/eslint --fix -c .eslintrc.js 'src/**/*.{js,jsx}'",
"start": "npm run lint && react-scripts start",
"startindocker": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"cypress": "npx cypress run",
"cypress:open": "npx cypress open",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
],
"devDependencies": {
"cypress": "^3.2.0",
"eslint": "^5.3.0",
"eslint-config-airbnb": "^17.1.0",
"eslint-config-prettier": "^5.0.0",
"eslint-plugin-import": "^2.17.3",
"eslint-plugin-jsx-a11y": "^6.2.1",
"eslint-plugin-prettier": "^3.1.0",
"eslint-plugin-react": "^7.14.1"
}
}发布于 2019-08-23 19:05:19
从node_modules中删除google-map-react文件夹并从package.json中删除,然后尝试npm install --保存google-map-react并检查node_modules文件夹google-map-react是否存在?
发布于 2019-08-24 13:42:12
尝试删除所有节点模块并重新安装,
rm -rf node_modules
npm install可能存在不兼容节点模块的问题。
https://stackoverflow.com/questions/57624234
复制相似问题