-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generate an ESM bundle #175
Comments
Sure I'm down - looking forward to the PR 🤙 |
ESM modules are now available in |
Hm the ESM module is breaking things #215 It seems to be related to some tricky circular dependency issues that are doing to take some time to figure out, so I'm removing the ESM module in @cbenz Can you try building your project and running the bundled version? It appears these issues often don't exist in a development environment then crop up in built/bundled versions. |
Actually the Snowpack dev tool I use, heavily focused on ESModules, has been upgraded in the last couple of days to enhance support of CommonJS modules, so I can now use zod without those native ESModules. Of course in the end ESModules should preferably be shipped for the browser platform rather than CommonJS, but in the meanwhile I'm not blocked anymore, so no problem for me if you remove them. |
Re-opening because the ES module was removed again in zod@2.0.0-beta.21. |
We seem to have an error related to this (and to #215). Currently experiencing this runtime error:
This happens with |
Yeah I took the ESM module out in beta21: #215 (comment) Gonna revisit the ESM bundling once I have time to debug these issues. 👍 |
We're kicking off a project using Snowpack, which compiles zod to ESM and has this circular dependency issue.. has anyone managed to work around it for now using Snowpack? |
I've run into the circular dependencies problem with Rollup as well, which makes sense b/c Snowpack is built on top of it. My use case is mainly for the |
FWIW, it's being worked on: rollup/plugins#658 |
@colinhacks FYI using the ESM built off the v2 branch with |
@colinhacks : @aaronjensen and @lukastaegert are using zod as a use-case for this PR. In this comment there is a custom Rollup plugin that may be able to create an ESM bundle for zod:
plugins: [
{
transform(code) {
return code.replace('var __importStar = (this && this.__importStar) || function (mod) {\n' +
' if (mod && mod.__esModule) return mod;\n' +
' var result = {};\n' +
' if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\n' +
' __setModuleDefault(result, mod);\n' +
' return result;\n' +
'};','var __importStar = function (mod) {\n' +
' return mod;\n' +
'};')
},
}
] |
Note that it still needs the commonjs plugin from the branch + manually enabling module side effects. To get rid of the latter issue, I will need to make a change in Rollup which will require some more time. |
@jacksteamdev @aaronjensen @lukastaegert @cbenz I'm having trouble reproducing these runtime issues with the ESM module like the ones described in #215. I'd love to see a PR for this, or at least a minimal repro. tbh all these module resolution subtleties are a little over my head. |
@colinhacks I'm not sure how to reproduce those issues either. They likely require a React Native build or, one person indicated a Next.js build. They likely have to do with the way that TS is converting to ES modules combined with the way that they're bundling combined with the particular circular dependencies that are in this repo triggering some edge case. It's messy stuff. The best bet is probably to get rid of the circular dependencies (likely easier said than done, I don't have my head wrapped around their cause in this repo) or implement the |
@mmeylan I'm having trouble reproducing the runtime issues with the ESM module you're describing. What's your build process? If you could throw together a reproduction repo that would be awesome. I'm trying to fix the issues with the Zod ES module over the weekend. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Hello! Would you be open to a pull request adding an ESM bundle? This would require roughly two changes:
build:esm
, building the project using a slightly modifiedtsconfig.json
and outputting todist/esm
(or similar).module
field topackage.json
pointing todist/esm/index.js
.If you are keen I am happy to PR :)
Thanks for the library!
The text was updated successfully, but these errors were encountered: