I'm currently working on an Angular 8 project that utilizes Webpack. My integration of Mapbox GL JS was successful, however, I am facing issues with importing Mabox GL Draw. Here are the versions I am using:
"@angular/core": "8.2.14",
"mapbox-gl": "^1.9.0",
"@types/mapbox-gl": "^1.8.2",
"@mapbox/mapbox-gl-draw": "^1.1.2",
Following the instructions provided in the Mapbox GL Draw documentation, I added the following line to my Angular Service:
import * as MapboxDraw from '@mapbox/mapbox-gl-draw';
Unfortunately, this resulted in the following error message:
TS7016: Could not find a declaration file for module '@mapbox/mapbox-gl-draw'. '/home/tommy/Work/engineering/effector/effector-gui/node_modules/@mapbox/mapbox-gl-draw/index.js' implicitly has an 'any' type. Please try
if available or add a new declaration (.d.ts) file containing `declare module '@mapbox/mapbox-gl-draw';npm install @types/mapbox__mapbox-gl-draw
After referring to this suggestion, I attempted using require instead of import:
const MapboxDraw = require('@mapbox/mapbox-gl-draw');
This led to another issue:
3:20 error Require statement not part of import statement @typescript-eslint/no-var-requires ERROR in ./node_modules/jsonlint-lines/lib/jsonlint.js Module not found: Error: Can't resolve 'fs' in '/home/user/proj/node_modules/jsonlint-lines/lib
My attempt to address this by modifying my tsconfig.json and installing "fs" via npm also generated an error:
This dependency was not found: * fs in ./node_modules/jsonlint-lines/lib/jsonlint.js To install it, you can run: npm install --save fs No type errors found
In order to resolve the initial error, I revisited the first solution and followed the steps outlined here. I made changes to my tsconfig.json file by adding the following values:
"typeRoots": ["node_modules/@types","./types"],
...
"exclude": ["node_modules","./types"]
Additionally, I created an index.d.ts file within three folders in types/@mapbox/mapbox-gl-draw/ with the following content:
declare module '@mapbox/mapbox-gl-draw';
However, this led to another error:
ERROR in undefined(undefined,undefined): TS2688: Cannot find type definition file for '@mapbox'.
Although I feel like I am close to finding a solution, I am unsure about how to proceed further.