TypeScript compile errors

2879
4
Jump to solution
07-15-2021 10:33 AM
BenRomlein
Occasional Contributor

I have a basic index.ts file:

 

import ArcGISMap from '@arcgis/core/Map';
import MapView from '@arcgis/core/views/MapView';
import Search from '@arcgis/core/widgets/Search';

const map = new ArcGISMap({
	basemap: 'topo-vector'
});

const view = new MapView({
	container: 'viewDiv',
	map: map,
	zoom: 10,
	center: [118, 34]
});

const search = new Search({
	view
});

view.ui.add(search, 'top-right');

 

and tsconfig copied from here.

When I do npx tsc I get several errors:

node_modules/@arcgis/core/interfaces.d.ts:1:1 - error TS6200: Definitions of the following identifiers conflict with those in another file: (Then a huge list)

node_modules/@types/arcgis-js-api/index.d.ts:8:1
8 type HashMap<T> = Record<string, T>;


Conflicts are in this file.

node_modules/@arcgis/core/interfaces.d.ts:31568:5 - error TS2687: All declarations of 'address' must have identical modifiers.

node_modules/@types/eslint/index.d.ts:451:42 - error TS2724: '"C:/Users/bromlein/Documents/snowpack-demo/node_modules/@types/estree/index"' has no exported member named 'ChainExpression'. Did you mean 'ThisExpression'?

451 ChainExpression?: ((node: ESTree.ChainExpression & NodeParentExtension) => void) | undefined;

node_modules/@types/eslint/index.d.ts:474:43 - error TS2694: Namespace '"C:/Users/bromlein/Documents/snowpack-demo/node_modules/@types/estree/index"' has no exported member 'ImportExpression'.

474 ImportExpression?: ((node: ESTree.ImportExpression & NodeParentExtension) => void) | undefined;

package.json:

 

{
  "name": "snowpack-demo",
  "version": "1.0.0",
  "description": "",
  "main": "./src/index.js",
  "scripts": {
    "start": "snowpack dev",
    "build": "snowpack build",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@snowpack/plugin-typescript": "^1.2.1",
    "@snowpack/plugin-webpack": "^3.0.0",
    "@types/arcgis-js-api": "^4.20.1",
    "snowpack": "^3.8.2",
    "tslib": "^2.3.0",
    "typescript": "^4.3.5"
  },
  "dependencies": {
    "@arcgis/core": "^4.20.2"
  },
  "browser": {
    "fs": false,
    "path": false
  }
}

 

what am I missing?

0 Kudos
1 Solution

Accepted Solutions
ReneRubalcava
Frequent Contributor II

Uninstall the types/arcgis-js-api. The ESM package comes with typings already.

View solution in original post

4 Replies
ReneRubalcava
Frequent Contributor II

Uninstall the types/arcgis-js-api. The ESM package comes with typings already.

BenRomlein
Occasional Contributor

So that knocked out all but two errors. Still getting 

node_modules/@types/estree/index"' has no exported member named 'ChainExpression'. Did you mean 'ThisExpression'?

 

and 

/node_modules/@types/estree/index"' has no exported member 'ImportExpression'.

 

removing node_modules and package-lock.json and running npm install again seems to have fixed this. Thanks for your help!

ReneRubalcava
Frequent Contributor II

I'm not sure exactly what your set up looks like, but I was able to put together a snowpack TS sample with the API without errors here.

https://github.com/odoe/snowpack-jsapi/tree/ts

I'm kind of surprised it worked, as there is an existing issue with snowpack here

https://github.com/snowpackjs/snowpack/issues/3322

Looks like that might be fixed now.

BenRomlein
Occasional Contributor

Nice. Works perfectly. Now I just need to dive in and figure out why the one I set up won't run snowpack dev.

I was pleasantly surprised snowpack build worked out of the box, too.

EDIT: After removing assets from the mount param from module.exports in snowpack.config.js, everything works now.

0 Kudos