3

When I am trying to import proj4 in my angular project I am getting an error

Error: export 'defs' (imported as 'proj4') was not found in 'proj4' (possible exports: default)

I am importing as

import * as proj4 from 'proj4';

Though I have installed the proj4 as

npm install --save @types/proj4

How can I solve this issue? Am I missing something here ?

2
  • Just check if you have exported proj4 from where it is defined? Commented Oct 11, 2021 at 17:04
  • 1
    Installing the types is not the same as installing the module. You need to install both the module and the types. The types belong in your devDependencies. Use --save-dev to install them in that location. Commented Oct 11, 2021 at 17:23

4 Answers 4

4

This import statement import * as proj4 from 'proj4'; used to work before year 2017 for v2.4 of proj4.

To use it for 2.4 and above, import it this way: -

import proj4 from 'proj4';

Also, you might need to do the following changes to your TypeScript compiler i.e. inside tsconfig.json: -

"allowSyntheticDefaultImports": true

These changes should do it.

Sign up to request clarification or add additional context in comments.

Comments

3

According to https://github.com/proj4js/proj4js/issues/247, for Typescript:

  • the import statement should be import proj4 from 'proj4';
  • and compiler option allowSyntheticDefaultImports: true must be set in tsconfig.json

This solved the issue for me for TypeScript 4.8 and Proj4 2.8.

Comments

2

I am using Angular 17 and I just ran the recommended action and it appears to have fixed the issue:

npm i --save-dev @types/proj4

Comments

1

The solution for me was to have both proj4 and @types/proj4 installed. Rather silly but if it works it works.

npm i proj4 --save
npm i @types/proj4 --save

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.