question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[compatability]: node + esm

See original GitHub issue

currently 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:closed
  • Created 3 years ago
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
KilianKilmistercommented, Sep 8, 2020

@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.

That being said, PRs and issues seem to go for months without any feedback, so, I suspect it will require someone to take it over completely, at some point.

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.

0reactions
bd82commented, Feb 27, 2021

closing this, will be tracked in: https://github.com/Chevrotain/chevrotain/issues/1383

Read more comments on GitHub >

github_iconTop Results From Across the Web

What does it take to support Node.js ESM? – The Guild
To add support ESM for Node.js, you have two alternatives: build your library into ESM Compatible modules with the extension .mjs , and...
Read more >
ECMAScript modules | Node.js v19.3.0 Documentation
Caveat: The ESM load hook and namespaced exports from CommonJS modules are incompatible. Attempting to use them together will result in an empty...
Read more >
Documentation - ECMAScript Modules in Node.js - TypeScript
For the last few years, Node.js has been working to support running ECMAScript modules (ESM). This has been a very difficult feature to...
Read more >
CommonJS (cjs) and Modules (esm): Import compatibility
ESM is supported by all modern browsers and the latest versions of Node, but does not work at all in Node versions below...
Read more >
Getting Started with (and Surviving) Node.js ESM
The Node.js ecosystem is shifting towards ESM. We examine what lies in store for application and library authors, learn some of challenges ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found