Issues with moving from esri-loader to ES Modules

1429
4
04-27-2021 11:24 PM
VivienWong
New Contributor II

I am trying to move my code from using esri-loader to using @argic/core in Javascript 4.19.  I have run these npm commands:

npm install @arcgis/core

npm install @types/arcgis-js-api@latest --save-exact

Then I updated my code with the “import … from '@arcgis/core/…;” statements and modified codes as needed.  When compile, it gives me “TS6200: Definitions of the following identifiers conflict with those in another file” on

node_modules/@arcgis/core/interfaces.d.ts

node_modules/@types/arcgis-js-api/index.d.ts

So, I tried remove “arcgis-js-api” from “types” in tsconfig.app.json and tsconfig.spec.json.  It now compiles.

VivienWong_0-1619590773383.png

However, when the map is being loaded, it hits a series of “TypeError:  Cannot convert undefined or null to object” and gives an empty map with no layers.

VivienWong_2-1619591046850.png

Any help is appreciated.  Thanks.

 

0 Kudos
4 Replies
ReneRubalcava
Frequent Contributor

When using the npm packages for @arcgis/core or arcgis-js-api, you don't need to install the typings separately. They packages already include them.

As for the second error, tough to debug without a repro sample to look at. Could be an issue that the element you're using for the map container isn't ready or something else.

0 Kudos
VivienWong
New Contributor II

Thanks Rene.  Do I need to uninstall the typings which I have installed separately?  Is it correct for me to exclude “arcgis-js-api” from “types” in tsconfig.app.json and tsconfig.spec.json?  

0 Kudos
ReneRubalcava
Frequent Contributor

You can uninstall the typings and you don't need to reference them in the tsconfig files.

The tsconfig in the TypeScript guide is a good reference https://developers.arcgis.com/javascript/latest/typescript-setup/#tsconfig

Although it assumes you are using the CDN and need the typings, but still no reference to them in the tsconfig.

The same goes for building an app with webpack as well.

https://github.com/Esri/arcgis-js-cli/blob/master/templates/webpack/app/tsconfig.json

 

0 Kudos
SteveBurdette
Occasional Contributor

Did you ever figure the second issue out?
I'm having the same problem but only when I publish my application and not on development.

0 Kudos