Documentation Request: Using a Node Custom Loader #3288
-
I really love ava, and I'm trying to build a case for using across all of our web projects at work. But I'm running into an issue trying to use ava to test Web Components using relative imports as JavaScript Modules in the browser. When I use ava I get the typical Node ESM Error:
I spent yesterday afternoon looking through your old bug reports, and your documentation on using ESM Loaders of various flavors, and I think the best way to go is using my own Node Custom Loader. Especially as there are special rules, such as: using Babel style imports, where extensions may be excluded for: What I can't find documented is how I would use my own custom loader with ava, assuming it's just a loader script running in my project. Example of running my custom loader: node --loader ./loader.mjs web/components/my-component.mjs Example of relative import from import MyOtherModule from '../my-other-module' // <-- loads '../my-other-module/index.mjs' Perhaps there is a simple way to do this already, which I have missed? I'm really just looking to use ava in a way that will respect a project level entry point to a If you guys are willing to help me get ava to work with a project based entry point to |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
This is an experimental Node.js feature. There are enough hooks within AVA ( |
Beta Was this translation helpful? Give feedback.
-
Recently, my "nodeArguments": [
- "--experimental-loader=@node-loader/core"
+ "--import=data:text/javascript,import {register} from 'node:module'; import {pathToFileURL} from 'node:url'; register('@node-loader/core', pathToFileURL('./'))"
], |
Beta Was this translation helpful? Give feedback.
This is an experimental Node.js feature. There are enough hooks within AVA (
nodeArguments
) and through environment variablesNODE_OPTIONS
to configure custom loaders. However the behavior keeps changing in Node.js so it tends to break a lot. There's plenty of discussion in this forum about all the different things to try.