In my TS file, I've included a 3rd party package using
import XXX { YYY, ABC, 123 } from 'XXX';
While it compiles to CommonJS without any issues, I'd prefer to have it compiled to an ESModule instead. I tried changing the target
and module
settings to esnext
in my TS config file, and although it compiles successfully, I encounter an error when running the file:
SyntaxError: Named export 'ABC' not found. The requested module 'XXX' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:
import pkg from 'XXX';
const { ABC } = pkg;
Are there any specific settings that I can utilize to instruct Typescript to convert the imports according to the import type mentioned in the error message?