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

fix: default exports not working on CJS + treeshake: true #815

Merged
merged 2 commits into from Feb 7, 2023

Conversation

csantos1113
Copy link
Contributor

Fixes #814

rollup v3 changed the interop behavior: https://rollupjs.org/guide/en/#outputinterop

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.

Source code example

Component

import ReactSelect from 'react-select'
      
export const Component = (props: {}) => {
  return <ReactSelect {...props} />
};

tsup flags

--treeshake --target es2022 --format cjs

tsconfig

{
  "compilerOptions": {
     "baseUrl": ".",
     "esModuleInterop": true,
     "isolatedModules": true,
     "jsx": "react-jsx",
     "lib": ["dom", "dom.iterable", "esnext"],
     "module": "esnext",
     "moduleResolution": "node",
     "noEmit": true,
     "rootDir": ".",
     "skipLibCheck": true,
     "sourceMap": true,
     "strict": true,
     "target": "es6",
     "importHelpers": true,
     "outDir": "dist"
  }
}

Output before this PR 🤕

'use strict';

var ReactSelect = require('react-select');
var jsxRuntime = require('react/jsx-runtime');

// input.tsx
var Component = (props) => {
  return /* @__PURE__ */ jsxRuntime.jsx(ReactSelect, {
    ...props
  });
};

exports.Component = Component;

Output after this PR 😎

'use strict';

var ReactSelect = require('react-select');
var jsxRuntime = require('react/jsx-runtime');

function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

var ReactSelect__default = /*#__PURE__*/_interopDefault(ReactSelect);

// input.tsx
var Component = (props) => {
  return /* @__PURE__ */ jsxRuntime.jsx(ReactSelect__default.default, {
    ...props
  });
};

exports.Component = Component;

@vercel
Copy link

vercel bot commented Jan 9, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
tsup ✅ Ready (Inspect) Visit Preview Jan 9, 2023 at 10:52PM (UTC)

@github-actions
Copy link

github-actions bot commented Feb 7, 2023

🎉 This PR is included 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 this pull request may close these issues.

default exports not working on CJS + treeshake: true
2 participants