-
Notifications
You must be signed in to change notification settings - Fork 1k
Support ES6 Modules #782
Comments
Make sure you're running a pretty recent version of Node. You need to add
Node documentation: https://nodejs.org/api/esm.html |
I suggest you package your backend service with webpack before using Pkg |
@gt-Lee Transpilation may not be neccesary with very modern node versions, which support ecmascript modules experimentally. Looks like he's trying to set that up. |
Hello, What is the current status of this issue? Using
The Using |
@erossignon any clue? |
I found a temporary work-around for this: Package everything into a single non-module JavaScript file using webpack. This is my
This will start at the root of your source tree (
to create the three binaries in the same directory. |
Hello @lkesteloot, I used esbuild with an additional plugin to manage native modules extracted from this esbuild issue. Still, using an additional bundler seems a bit cumbersome as |
Check out https://github.com/vercel/ncc . It is quite easy to use. |
What would be nice would be for The root issue here is that tools like babel, swc, and ncc don't follow imports like pkg does. We just need a way to merge the two. |
If your target Node version already supports modules then shouldn't |
@rightaway FWIU To support ES6 modules, it has to do the same for |
@gautaz If it relies on babel maybe there could be some way to customize the options passed to babel so we can tell if we're using ES6 modules? @jesec @igorklopov Is it in the eventual roadmap to offer support for ES6 modules or will it not be in the scope of |
I tried both |
I was just using an external library from It's been almost one and half years since the issue was opened and no packagers currently support bundling native ESM modules. Tried |
@vasanthdeveloper Which library is it? |
It's itivrutaha, and I fixed this issue by migrating to |
@vasanthdeveloper how did you run it? I am still getting errors with this: esbuild --bundle --target=node10 --outdir=./dist --platform=node ./crossaudio.js && pkg --public --out-path dist/ ./dist/crossaudio.js When I try to run the result on mac or linux:
My project is here Even when I try to run the resulting bundle:
But the source is fine:
If I do this to force cjs extension:
I get same error when I run the build product:
|
For those using Typescript, set "target": "ES2020",
"module": "commonjs", inside your |
Any word on this? ESM has been in the works for years and is now fully supported in active and current Node versions – transpilation should not be a necessary step to using ESM in 2021. This issue in particular has been open for two years. Related: is this project being actively improved, or is it in bug fix / maintenance mode? Checking in on key issues / offers for PRs have gone unresponded to; I see that occasional maintenance releases are still being occasionally cut, but as far as maintainer participation it seems like crickets here in the issue tracker. It's totally cool if this project is no longer being actively improved or if PRs just aren't welcomed, but some guidance from the maintainers would be helpful in setting expectations. |
Feel free to open PRs, we can check them out 😄 As long as there's proper testing, I see no issue adding new features! |
@ryanblock please let us know if find a way to make it work :) |
If it can help others, i moved to caxa which handle ESM out-of-the-box. |
@ryanblock I don't expect much to happen with https://github.com/leafac/caxa looks very good. Responsive maintainer and works with ES6 modules and native modules. |
@leerob given the conversation that's ensued, thoughts on the other part of my question ( |
It is straightforward to implement. We just have to support tracing of dependencies for ES6 "import", like what we currently did for CommonJS (see walker.ts). However, I would rather not reinvent the wheel, since nft does just that. #1138 would be the prerequisite for ES6 module support. At the moment, I recommend users to use a bundler like esbuild or webpack to transpile to CommonJS style import. If you use TypeScript, simply specify |
Thanks for the context, @jesec! Imo bundling esm to cjs is totally out of the question. Call me crazy, but I like usable stack traces! |
caxa doesn't hide the source code in any way Right? its a big no for me |
@Nisthar it will leafac/caxa#21 |
I'm trying to package a node app as an exe using pkg, and I'd like to use ES6 imports.
I have something like this in my src/app.js:
in my package.json I have:
npm start works fine
but
npm run build
gives a waning and then running the exe throws an error:It seems like the
--options experimental-modules
parameter from the build script in package.json is not beign taken into account.Any idea how can I use ES6 module imports from a node app packaged with pkg?
PS: also asked at SO in case anybody wants to raise their reputation
The text was updated successfully, but these errors were encountered: