【问题标题】:Erro in ReactJS - Module not found: Can't resolve 'highcharts'React JS 中的错误 - 找不到模块:无法解析“highcharts”
【发布时间】:2020-01-21 14:36:53
【问题描述】:

我在一些使用纯 Javascript 的项目中使用 Highcharts。现在我用 ReactJS 开始一个新项目,并在上面安装 highcharts。

npm install -g highcharts highcharts-react-official

但是当我使用

启动项目时
yarn start

我收到以下错误:

Module not found: Can't resolve 'highcharts'

这是我使用命令时得到的

npm list -g --depth 0

E:\Programas\NodeJS\node-v10.16.3-win-x64
+-- axios@0.19.0
+-- create-react-app@3.1.1
+-- eslint@6.4.0
+-- highcharts@7.2.0
+-- highcharts-react-official@2.2.2
+-- my-app@0.1.0 -> E:\PUC\RelatorioCanvas\reactJs
+-- npm@6.9.0
+-- react@16.9.0
+-- react-scripts@3.1.1
+-- typescript@3.6.3
`-- yarn@1.17.3

npm ERR! peer dep missing: typescript@*, required by @typescript-eslint/eslint-plugin@1.6.0
npm ERR! peer dep missing: typescript@*, required by @typescript-eslint/parser@1.6.0
npm ERR! peer dep missing: typescript@*, required by ts-pnp@1.1.2
npm ERR! peer dep missing: typescript@*, required by @typescript-eslint/parser@1.6.0
npm ERR! peer dep missing: typescript@*, required by @typescript-eslint/typescript-estree@1.6.0
npm ERR! peer dep missing: typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta, required by tsutils@3.17.1
npm ERR! peer dep missing: typescript@*, required by @typescript-eslint/typescript-estree@1.6.0
npm ERR! peer dep missing: typescript@*, required by ts-pnp@1.1.2
npm ERR! peer dep missing: eslint@^5.0.0, required by @typescript-eslint/eslint-plugin@1.13.0
npm ERR! peer dep missing: eslint@^5.0.0, required by @typescript-eslint/parser@1.13.0

我已经安装了 highcharts 和 highcharts-react-official,但问题仍然存在。

我该如何解决这个问题?

【问题讨论】:

    标签: highcharts react-highcharts


    【解决方案1】:

    您可能需要安装 typescript 版本的 highcharts。

    npm install @types/highcharts
    

    【讨论】:

      【解决方案2】:

      我找到了导致问题的原因。

      我使用 -g 选项安装所有内容。这些包是全局安装的,现在我将它们作为依赖项放在我的项目中并使用 npm install。

      现在完美运行。

      这就是我的 package.json 现在的样子

      {
        "name": "my-app",
        "version": "0.1.0",
        "private": true,
        "dependencies": {
          "axios": "^0.19.0",
          "react": "~16.8.6",
          "react-dom": "^16.8.6",
          "highcharts": "^6.0.0",
          "typescript": "^2.8.0",
          "highcharts-react-official": "^2.2.0",
          "eslint": "^5.0.0",
          "react-scripts": "3.0.1"
        },
      

      【讨论】:

        猜你喜欢
        • 2020-11-15
        • 1970-01-01
        • 2016-10-27
        • 2021-10-11
        • 2017-03-31
        • 1970-01-01
        • 2021-04-05
        • 2019-08-13
        • 1970-01-01
        相关资源
        最近更新 更多