ES Modules: '@arcgis/core/geometry/projection' does not contain a default export'

852
2
Jump to solution
04-26-2021 07:39 AM
JamesGough
Occasional Contributor

I am testing out the new ES Modules option in 4.19 by migrating one of my apps from ESRI Loader to ES Modules. The app uses React and was created using Create React App.

I am having issues importing the "projection" module. For example if I try to import it as below I get a compile time error:

import projection from "@arcgis/core/geometry/projection";

// Failed to compile.
// ./src/map/MainMap.tsx
// Attempted import error: '@arcgis/core/geometry/projection' does not contain a default export (imported as 'projection').

 

Additional version info:

    "@arcgis/core""^4.19.1",
    "react""^17.0.0",
    "react-scripts""4.0.3",
    "typescript""^3.7.5"

 

How should I import this module?

 

 

0 Kudos
1 Solution

Accepted Solutions
ReneRubalcava
Frequent Contributor

The syntax would look like this.

import { load, project } from '@arcgis/core/geometry/projection';

 

You could import the entire module like this.

import * as projection from '@arcgis/core/geometry/projection';

However this will load all the methods of projection, even if you don't use them. It's a minimal impact on built javascript, but the first way allows build tools to only include code you use.

View solution in original post

2 Replies
ReneRubalcava
Frequent Contributor

The syntax would look like this.

import { load, project } from '@arcgis/core/geometry/projection';

 

You could import the entire module like this.

import * as projection from '@arcgis/core/geometry/projection';

However this will load all the methods of projection, even if you don't use them. It's a minimal impact on built javascript, but the first way allows build tools to only include code you use.

JamesGough
Occasional Contributor

Perfect, thanks Rene! 

0 Kudos