我正在使用 Webpack 开发 Angular 8 项目。我能够集成Mapbox GL JS,但我不知道如何导入Mabox GL Draw。我有以下版本:
"@angular/core": "8.2.14",
"mapbox-gl": "^1.9.0",
"@types/mapbox-gl": "^1.8.2",
"@mapbox/mapbox-gl-draw": "^1.1.2",
我关注了 Mapbox GL Draw docs,所以在我的 Angular 服务中,我添加了:
import * as MapboxDraw from '@mapbox/mapbox-gl-draw';
所以我有这个错误:
TS7016:找不到模块“@mapbox/mapbox-gl-draw”的声明文件。'/home/tommy/Work/engineering/effector/effector-gui/node_modules/@mapbox/mapbox-gl-draw/index.js' 隐含了一个 'any' 类型。尝试
npm install @types/mapbox__mapbox-gl-draw
它是否存在或添加一个包含 `declare module '@mapbox/mapbox-gl-draw' 的新声明 (.d.ts) 文件;
按照这个建议,我尝试使用require而不是import:
const MapboxDraw = require('@mapbox/mapbox-gl-draw');
我有这个:
3:20 错误 Require 语句不是导入语句的一部分 @typescript-eslint/no-var-requires ./node_modules/jsonlint-lines/lib/jsonlint.js 中的错误模块未找到:错误:无法解析“fs” '/home/user/proj/node_modules/jsonlint-lines/lib
所以我尝试遵循这个,我修改了我的tsconfig.json并通过 npm "fs" 安装。但是会出现错误:
没有找到这个依赖: * fs in ./node_modules/jsonlint-lines/lib/jsonlint.js 要安装它,你可以运行: npm install --save fs No type errors found
所以我决定回到第一个错误,我跟着这个。我修改了 tsconfig.json文件添加了这些值:
"typeRoots": ["node_modules/@types","./types"],
...
"exclude": ["node_modules","./types"]
比我在这三个文件夹 types/@mapbox/mapbox-gl-draw/ 中创建index.d.ts文件的内容
declare module '@mapbox/mapbox-gl-draw';
但我得到这个错误
未定义(未定义,未定义)中的错误:TS2688:找不到“@mapbox”的类型定义文件。
现在我觉得离解决方案很近了,但我现在不知道如何走得更远。