-
Notifications
You must be signed in to change notification settings - Fork 1
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
fix #5 due to no esmodule #6
base: main
Are you sure you want to change the base?
Conversation
I've tried your fork, but you only have the fix for ESM. I'm using esbuild to bundle for serverless, which ends up being a CJS environment (node 18). So I'm trying to bundle ESM to CJS, while importing a module that has a CJS file, which has a Zod import, which as we know, breaks Maybe it's worth adding an exports map? That might cause ESBuild to use the ESM version when importing, and compile it to CJS so that it shares the CJS Zod import? Something like "exports": {
"types": {
"import": "dist/esm/index.d.ts",
"require": "dist/cjs/index.d.ts"
}
"import": "dist/esm/index.js",
"require": "dist/cjs/index.js"
}
I had a look at the build artifacts and Zod is already externalised. So the problem stems from the fact that when targeting CJS (which is necessary when using the Serverless framework for deploying to AWS Lambda), the CJS version is being resolved. So the only way I can see this problem being resolved is with the Exports map. The JS ecosystem has struck again |
Additionally, the ESBuild docs state the following
Unfortunately for me, I'm unable to set the main fields setting to |
"types": "dist/index.d.ts", | ||
"main": "dist/cjs/index.js", | ||
"module": "dist/esm/index.js", | ||
"types": "dist/cjs/index.d.ts", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used yarn patch
to try the exports map, and can confirm that it solves the ESBuild problem.
"types": "dist/cjs/index.d.ts", | |
"types": "dist/cjs/index.d.ts", | |
"exports": { | |
"types": { | |
"import": "./dist/esm/index.d.ts", | |
"default": "./dist/cjs/index.d.ts" | |
}, | |
"import": "./dist/esm/index.js", | |
"default": "./dist/cjs/index.js" | |
}, |
@parisholley I don't suppose you've got notifications disabled for this PR, have you? I can confirm that the exports map works perfectly |
No description provided.