Additional target for NodeJS ES Modules (MJS)
Closed this issue · 14 comments
I was hoping to use import moize from 'moize/es
but the target looks like it is umd and not node es modules. Would be nice to have an additional target with .mjs
files for import with NodeJS experimental modules.
The es
implementation was written with browser standards in mind. Based on my (admittedly limited) understanding of Node's implementation, it is the same syntax as the es
files just with the .mjs
file extension, correct?
As far as I can tell you are correct.
Cool that makes it easy ... putting together a PR that does a simple copy / rename of the es
folder output as part of the build process. Should be up shortly.
The way you'll use it is:
import moize from 'moize/mjs';
I added the PR if you wanna take a look ... seems pretty straightforward, but a fresh set of eyes is always helpful.
I renamed the files to test and I got this error. Need to dig into it more and find out why:
SyntaxError: The requested module does not provide an export named 'orderByLru'
at ModuleJob._instantiate (internal/loader/ModuleJob.js:85:17)
at
EDIT: I think micro-memoize is also not set up for nodejs modules. I don't think it is as easy as renaming the files since there are nested dependencies.
I think I know what it is ... I am specifically importing that function from micro-memoize/es/utils
.
Basically, I need to provide the same .mjs
enhancement to micro-memoize
, publish it, and then modify the import in moize
the way I do currently between es
and lib
to point to micro-memoize/mjs/utils
. I may not get to this tonight, but it should be ready in a day or two.
EDIT: come to think of it ... will this work with any external dependencies that aren't Node ESM-compatible? Because I may need to do the same to fast-stringify
.
I renamed those files and it looks like deepEqual
(from fast-equals) also is not a proper mjs. This might be more difficult than originally anticipated.
EDIT: It looks like fast-equals is also your module. I'll try renaming those files and see how deep this rabbit hole goes.
Yeah I just checked ... I think it needs to be .mjs
turtles all the way down. Luckily, I own all of these packages (:wink:), so I can definitely add them ... but it may take a few days.
So if I do the following:
import memoize from 'micro-memoize/mjs';
import { deepEqual, sameValueZeroEqual, shallowEqual } from 'fast-equals/mjs';
And do the rename/folder for those modules, then it loads.
Whenever you get time, it would be awesome!
Well that is good news ... at least the theory holds!
Alright well then I'll get to work doing this to those other packages, and report back here once ready to check again.
EDIT: In the meantime, you could always just use @std/esm
Ohh I didn't even know about that. Yeah it does the chore of doing a require (instead of import) and re-exporting. Thanks!
Alright I've updated all the sub packages, and the build process to use the mjs versions. If you want to check it out, I'd appreciate the feedback.
Sorry, I am out of town for 3 weeks. I'll check it out and get back to you.
No worries, I was actually able to verify it myself with a simple test file ... Worked as expected. This change was released as 5.4.0
.