suggest: Support ES Modules #1153
Replies: 8 comments
-
Also encountered this issue today, this is pretty ugly:
In the past I used microbundle to fix this:
|
Beta Was this translation helpful? Give feedback.
-
I am also wondering about the inclusion of dependencies in the bundled artifacts. Normally the dependencies would be installed and imported by package.json, but all the dependencies with this library are included in the code. |
Beta Was this translation helpful? Give feedback.
-
Thanks for the recommendations yall. Bundling is always the trickiest part of any node project 😜 We don't have the bandwidth to polish up our bundling process at the moment, but we'll be putting some work into docs, cleaning up the SDK & doing some bundling soon. Hang with us! |
Beta Was this translation helpful? Give feedback.
-
@dholms On the other hand, I think including dependencies in the library code is a big problem. Normally, the appropriate platform and module system code should be selected by the bundler, but currently, this is not possible. I think this problem can be fixed with a slight rewrite of the existing build scripts, can I send you a PR? |
Beta Was this translation helpful? Give feedback.
-
Sure shoot one in & I'll take a look at it 👍 |
Beta Was this translation helpful? Give feedback.
-
We started using scw for testing, but not for builds yet. I had that in mind for reworking our build system: https://swc.rs/ It supports compilation but not bundling |
Beta Was this translation helpful? Give feedback.
-
uhhhh how are people getting around this? I really need remedial node module resolution 101 class I have an app that was working great with https://astro.build locally, but when I pushed it to Vercel (with the normal Astro Vercel plugin) I get a runtime error
so I switched it to using that import syntax and now it's breaking locally import pkg from '@atproto/api';
const { BskyAgent } = pkg; super respect that changing the build system isn't a priority right now, but I'm totally spacing on how to resolve something like this and it's blockin me will prob just refactor to Next.js before I'm too far down this rabbit hole bc it's more of a known-quantity in the ecosytem UPDATE incase this helps anyone else, gpt4 told me to make a wrapper module - fixes it locally but broken again on vercel. i'm probably gonna refactor to Next while I still have my attention space but this is the snippet // src/utils/atp.mjs
import { createRequire } from "module";
const require = createRequire(import.meta.url);
export const ATP = require("@atproto/api"); |
Beta Was this translation helpful? Give feedback.
-
Yeah, I think Astro just doesn't support this at all withastro/astro#3174 (comment) Ran into this same issue tonight. Astro site working fine locally, Would be really great if ESM support could be provided 💙 |
Beta Was this translation helpful? Give feedback.
-
These libraries are currently output in CommonJS format and seem not to support ES Modules.
If ES Modules were supported, the bundler would work effectively and it would be easier to embed the library into applications.
Currently, you are using ESBuild to build, are there any plans to support both CommonJS and ES Modules using like unbuild or similar?
Thank you so much for developing this wonderful library and protocol!
Beta Was this translation helpful? Give feedback.
All reactions