Babel-node does not transpile files references by workers. Can/should it?
See original GitHub issueI find that using new Worker(file.js)
(and file.js uses import statements), that babel loads the referenced script fine but babel-node doesn’t. Is this a bug or related to how babel-node works (my understanding of these things is not so good)?
I have just posted a StackOverflow question with more detail: https://stackoverflow.com/questions/59662352/how-to-get-babel-node-to-convert-files-referenced-by-workers-to-commonjs-like
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
How to get babel-node to convert files referenced by Workers ...
Babel converts all the files to commonjs, and loading the worker script works. BUT. When I use @babel/node , this doesn't work: babel-node...
Read more >babel/node - Babel.js
babel -node is a CLI that works exactly the same as the Node.js CLI, with the added benefit of compiling with Babel presets...
Read more >TypeScript rules for Bazel - GitHub Pages
This will produce an opaque directory of .js file outputs, which you won't be able to individually reference. Any other use case for...
Read more >Build Performance - webpack
The thread-loader can be used to offload expensive loaders to a worker pool. warning. Don't use too many workers, as there is a...
Read more >Comparing Babel, Sucrase, and Similar Libraries
These browsers do not necessarily need to be compatible with the just added JavaScript feature. Here is an example of how Babel transpiles...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
babel-cli
transforms all the JavaScript files inside thesrc
folder. It operates on per-file level and does not process the module references.Under the hood
babel-node
uses pirates, which overwritesModule._extension[".js"]
. So when a module is loaded, the babel transform defined here will be executed: https://github.com/babel/babel/blob/a0a9c64a470acec77bec1da0b4bceec4ccf7f446/packages/babel-register/src/node.js#L62The
Worker
constructor does not invokeModule
constructor so babel-node could not hook into the loader and apply the transformation. You can use@babel/register
to hook into any files loaded inside your worker:file-wrapper.js
main.js