ESM error when trying to import Map from "@arcgis/core/Map" from ESRI JSAPI v4.20 on CRA

296
1
09-08-2021 05:13 AM
KenjooYeap
New Contributor II

Hi, 

I am trying to write tests using the create react app example and am getting the following error:  

KenjooYeap_0-1631102818643.png

 

To reproduce the error: 

-  `git clone https://github.com/Esri/jsapi-resources.git`

- npm i

- go to create-react-app example 

- add `import Map from "@arcgis/core/Map";`

- replace "MapView" with "Map"

- `npm run test`

 

Any help would be much appreciated!

0 Kudos
1 Reply
ReneRubalcava
Frequent Contributor II

If you add new ArcGIS imports into modules you're testing or change them, you need to add new mocks as well. The mocks are located here.

https://github.com/Esri/jsapi-resources/tree/master/esm-samples/jsapi-create-react-app/src/__mocks__...

You might be able to use transformIgnorePatterns, but I couldn't get it to work with CRA.

https://jestjs.io/docs/configuration#transformignorepatterns-arraystring

Might need some more jest config options. It works in this angular demo, but CRA complains about some stuff.

https://github.com/andygup/angular-jsapi-jest

0 Kudos