[compatability]: node + esm
See original GitHub issuecurrently trying to use named imports with chevrotain throws an error:
SyntaxError: The requested module 'chevrotain' is expected to be of type CommonJS, which does not support named exports. CommonJS modules can be imported by importing the default export.
For example:
import pkg from 'chevrotain';
const { createToken, Lexer } = pkg;
Node will also only see the non-esm version since it ignores the module
field in the package.json.
There are two fixes for this: conditional exports, nested exports (links to the docs).
And in either way, there needs to be a package.json
with the property "type": "module"
for node to recognize it as an ESM somewhere above it in the tree. (eg. in the ts outDir
)
Lack of this also effectively causes the typedefinitions to be incorrect, as they claim the package does have named exports
Additionally, setting the TS target
for esm to es5
makes little sense, as there is no esm in es5. it should be set to at least es6, since that would also mean that the outputted files use those es6 features that help static analyzers.
EDIT (VITAL): node also requires file extentions to be added to import specifiers (follwing esm-spec)
Issue Analytics
- State:
- Created 3 years ago
- Comments:12 (4 by maintainers)
Top GitHub Comments
@MikeActually I’ve read through the relevant discussions about this a few days ago, and we will have to see what the result of the dispute claim will be.
I can say right of the bat, until something changes that, i’m not going to do any work on lerna.
I’m going to continue this in your issue thread in the lerna repo because it’s not the topic of this thread.
closing this, will be tracked in: https://github.com/Chevrotain/chevrotain/issues/1383