Skip to content
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

default exports not working on CJS + treeshake: true #814

Closed
csantos1113 opened this issue Jan 9, 2023 · 2 comments · Fixed by #815
Closed

default exports not working on CJS + treeshake: true #814

csantos1113 opened this issue Jan 9, 2023 · 2 comments · Fixed by #815
Labels

Comments

@csantos1113
Copy link
Contributor

csantos1113 commented Jan 9, 2023

    I'm having an issue after upgrading to `6.4.0` bundling to CJS.

Here is a simplified version of my react code:

// Component.tsx

import ReactSelect from 'react-select';

const Comp = (props) => {
  return <ReactSelect {...props} />
}
// tsup.config.ts

export default {
  bundle: true,
  clean: true,
  dts: true,
  format: ['cjs', 'esm'],
  minify: false,
  sourcemap: true,
  splitting: true,
  target: 'es2022',
  treeshake: 'smallest'

The generated CJS file with tsup v6.3.0 was working ✅

var ReactSelect = require('react-select');
var ReactSelect__default = /*#__PURE__*/_interopDefaultLegacy(ReactSelect);

var Comp = (props) => {
  return /* @__PURE__ */ jsxRuntime.jsx(ReactSelect__default["default"], { ...props });
}

The generated CJS file with tsup v6.4.0 isn't working ⚠️

var ReactSelect = require('react-select');
var Comp = (props) => {
  return /* @__PURE__ */ jsxRuntime.jsx(ReactSelect, { ...props });
}

Do you know if there is additional rollup configuration I need to pass to have rollup resolving default exports properly?

Originally posted by @csantos1113 in #749 (comment)

Upvote & Fund

  • We're using Polar.sh so you can upvote and help fund this issue.
  • We receive the funding once the issue is completed & confirmed by you.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar
@csantos1113
Copy link
Contributor Author

Reading this piece of Rollup documentation: https://rollupjs.org/guide/en/#outputinterop it says:

Note that the default mode of "default" mimics NodeJS behavior and is different from TypeScript esModuleInterop. To get TypeScript's behavior, explicitly set the value to "auto". In the examples, we will be using the CommonJS format, but the choice of interop similarly applies to AMD, IIFE and UMD targets as well.

So I wonder if we should add interop: 'auto' here 👇

const result = await bundle.generate({
format: this.format,
file: 'out.js',
sourcemap: !!this.options.sourcemap,
name
})

@github-actions
Copy link

github-actions bot commented Feb 7, 2023

🎉 This issue has been resolved in version 6.6.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant