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.

[Feature] Allow users to specify a custom `experimental-loader` when using `esm`

See original GitHub issue
  • I’d be willing to implement this feature (contributing guide)
  • This feature is important to have in this repository; a contrib plugin wouldn’t do

Sadly can’t contribute without jumping through some significant hurdles.

Describe the user story

Using yarn with the .pnp.loader.mjs experimental loader prevents users from adding their own loader. If we specify it on the command line, we lose yarn’s loader. Node doesn’t currently support multiple loaders, and even if it did, not sure how this will look in future. Since yarn expects the loader to be called .pnp.loader.mjs (hard coded in the source), and this file is automatically generated - users of yarn don’t have an option but to use it.

Describe the solution you’d like

Allow users specify the experimental loader to use in yarmrc or something similar. Yarn can still generate the .pnp.loader.mjs file, but advanced users can import from the original .pnp.loader.mjs file and re-export their custom hooks (which build on top of the .pnp.loader.mjs hooks).

Describe the drawbacks of your solution

This is an opt-in feature, and using it essentially means you know what you are doing. More config is never better, but my request is basically for the name of the experimental loader to use not to be hard-coded.

Describe alternatives you’ve considered

We could always incorporate the experimental loader and override it ourselves, e.g:

yarn node --experimental-loader ./.pnp.loader-extended.mjs ./main.mjs

But the above only complicates things (sometimes yarn is run as a script, do we manually add this everywhere?). What if yarn is run in another processes?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
arcaniscommented, Nov 4, 2021

If and when loader chaining is implemented, would the expectation be for users to manually include Yarn’s loader via the CLI?

I’d expect it to work the same as for commonjs: Yarn adds --loader .pnp.mjs to the NODE_OPTIONS variable (just like we do with --require), and to add more loaders you’d add more --loader options to your own command line. But it’s not specific to Yarn, it’s how Node works.

1reaction
arcaniscommented, Jun 9, 2022

It’s not a bug, it’s a separate feature: loaders can be composed, but don’t yet leverage earlier loaders when resolving subsequent ones. I submitted a RFC and there’s been reasonable support for fixing that, but I didn’t get the chance to implement it yet.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Make anything a JavaScript module using Node.js ESM ...
Finally, run your project, telling Node to use your new loader: node --experimental-loader=node-esm-loader .
Read more >
(node:9511) ExperimentalWarning: The ESM module loader is ...
I realize after a few tries that "--experimental-modules" flag on the "nodemon" causes issues ...
Read more >
ECMAScript modules | Node.js v19.3.0 Documentation
In current Node.js, specifiers starting with https:// are experimental (see HTTPS and HTTP imports). The loader below registers hooks to enable rudimentary ...
Read more >
Experiments | webpack
Enable native CSS support. Note that it's an experimental feature still under development and will be enabled by default in webpack v6, however...
Read more >
Using the Node.js agent in an ES module application
Since Node.js v12.0.0, support for ECMAScript modules (ES modules/"ESM") has been added. ... ES modules are the official ECMAScript standard for code management ......
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