获取谷歌地图反应库加载

时间:2019-08-23 10:18:10

标签: javascript reactjs google-maps npm

在现有应用程序中,我在本地安装了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'

我注意到第二个错误中引用的路径不正确。当我的应用位于/usr/local

中时,它指的是~/www/...

我不清楚我在做什么错。该库未全局安装,我运行了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"
  }
}

2 个答案:

答案 0 :(得分:0)

从node_modules中删除google-map-react文件夹,然后从package.json中删除,而不是尝试 npm install-保存google-map-react ,然后在node_modules文件夹内检查google-map-react是否存在?

答案 1 :(得分:0)

尝试删除所有节点模块并重新安装,

rm -rf node_modules
npm install

节点模块不兼容可能有问题。