打字稿找不到模块

时间:2019-12-12 18:01:17

标签: typescript node-modules

我正在尝试在Visual Studio 2019上使用Typescript导入模块。

import * as Highcharts from 'highcharts';
(<any>window).Highcharts = Highcharts;

结果:

  

错误TS2307(TS)找不到模块'highcharts'。
  错误TS2307内部版本:找不到模块   '../node_modules/highcharts'。

这是我的tsconfig.json

{
  "compilerOptions": {
    "noImplicitAny": true,
    "noEmitOnError": true,
    "removeComments": false,
    "sourceMap": true,
    "target": "ESNext"
  },
  "include": [
    "**/*"
  ],
  "exclude": [
    "node_modules",
    "wwwroot"
  ],
  "compileOnSave": true
}

这是我的packages.json:

{
  "version": "1.0.0",
  "name": "asp.net",
  "private": true,
  "devDependencies": {
    "gulp": "4.0.2",
    "del": "5.1.0",
    "highcharts": "8.0.0"
  }
}

如果我查看依存关系=> npm,则显示高图。如果我在node_modules文件夹中查找,则存在highcharts。

我想念什么?我是在Typescript中使用模块的新手,但是我在Google上找到的所有内容似乎都与我的设置类似。

1 个答案:

答案 0 :(得分:1)

根据高图自述文件,您需要将其导入为

import Highcharts from 'highcharts';

然后您需要更新tsconfig.json文件

{
  "compilerOptions": {
    "allowSyntheticDefaultImports": true,
    "esModuleInterop": true,
    "baseUrl": "./",
    "module": "es6",
    "moduleResolution": "node",
    "target": "es6",
    "paths": {
      "https://code.highcharts.com/es-modules/masters/*.src.js": [
        "node_modules/highcharts/*.src"
      ]
    }
  }
}

检查此 https://github.com/highcharts/highcharts#typescript--umd