I have a web-app that depends on the @arcgis/core
-package;
"dependencies": {
"@arcgis/core": "^4.23.7",
"@types/arcgis-js-api": "^4.23.1",
"@vertigis/arcgis-extensions": "^35.0.1",
"@vertigis/viewer-spec": "47.6.0"
}
The package itself - from my understanding - also emits ES-modules, as it contains "type": "module"
:
{
"name": "@arcgis/core",
"version": "4.23.7",
"homepage": "https://js.arcgis.com",
...
"dependencies": {
"@esri/arcgis-html-sanitizer": "~2.9.0",
"@esri/calcite-colors": "~6.0.1",
"@esri/calcite-components": "1.0.0-beta.77",
"@popperjs/core": "~2.11.4",
"focus-trap": "~6.7.3",
"luxon": "~2.3.1",
"sortablejs": "~1.14.0"
},
"type": "module"
}
When I run npm build
everything is fine and I get a transpiled main.js
-file within my build
-directory.
However when I try to exexute the code using jest
, I get
SyntaxError: Cannot use import statement outside a module
> 1 | import FeatureLayer from "@arcgis/core/layers/FeatureLayer"; | ^
which I don't understand, as the package's type is set to module
as shown above.
My jest.config.js
is this:
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'jsdom',
transform: {
"^.+\\.tsx?$": "ts-jest"
},
transformIgnorePatterns: [
"node_modules/.*"
]
};
I also tried with preset: 'ts-jest/presets/js-with-ts',
as suggested in https://stackoverflow.com/a/71545273/2528063