Home > Net >  Using ESM and Commonjs within one project in typescript
Using ESM and Commonjs within one project in typescript

Time:01-28

Is it possible to use ESM only and Commonjs only modules in one project?

I'm using typescript to compile and my problem is that certain packages support only ESM and certain only Commonjs, so when I'm trying to compile on changing the module output with the compiler I'm getting an error:

when using compiler option module: "ES2020"

SyntaxError: Cannot use import statement outside a module

and the other way around when using commonjs.

CodePudding user response:

In your package.json

you should have

{...
  "type": "module",
...}
  •  Tags:  
  • Related