-
-
Notifications
You must be signed in to change notification settings - Fork 229
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
Possible to have export default
emit as module.exports
#572
Comments
+1. It isn't obvious what the fix is when trying to write modules with |
You can re-export it in another file: module.exports = require('./dist/index').default And use this file in the |
FWIW, I solved this by adding this to my tsup config – import { defineConfig } from 'tsup'
export default defineConfig({
splitting: false,
sourcemap: false,
minify: true,
clean: true,
+ esbuildOptions: (options) => {
+ options.footer = {
+ // This will ensure we can continue writing this plugin
+ // as a modern ECMA module, while still publishing this as a CommonJS
+ // library with a default export, as that's how ESLint expects plugins to look.
+ // @see https://github.com/evanw/esbuild/issues/1182#issuecomment-1011414271
+ js: 'module.exports = module.exports.default;',
+ }
},
entry: ['src/index.ts'],
}) See getoslash/eslint-plugin-tap#36 for reference. |
We can manually do that in our personal file, but maybe in some runtime env like ESlint couldn't do that. |
I am wondering why |
Everyone, I created a library of fix-tsup-cjs to solve this problem. It can also fix Related issues: #255 #283 #338 #572 #710 |
🎉 This issue has been resolved in version 7.2.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Should this issue be closed? I find that I still need the |
Could you please provide a minimum reproduction repo? |
Here's a GitHub repo that reproduces the issue: https://github.com/psirenny/tsup-cjs-default-export The source directory has a module exporting a default string. There's a |
@psirenny Because of issue evanw/esbuild#3281, we have to also enable |
Aha, that does indeed do the trick. Thanks for explaining that! |
@sxzz |
See evanw/esbuild#3281. In CJS mode, esbuild didn't generate valid export metadata. I think it's a bug of esbuild. So it blocked using For docs, maybe someone can submit a PR for mentioned that. |
I know it's not the preferred way of having a default export, but it would save a lot of time if this would be possible. I'm writing an ESLint plugin and currently cannot import the plugin into a CJS file because the module is exported as
module.exports.default
rather than simplymodule.exports
.Have only come across this issue which I wasn't able to find a way to implement it properly: #283 and also #255 but I got the warnings below:
Thanks!
Upvote & Fund
The text was updated successfully, but these errors were encountered: