0

I have a react component library that worked with react scripts 4. The library is dependent on @headlessui/react, so that is in my node_modules, but not required directly by the application, only by the component library.

I'm running into this problem: react-script 4 to 5 migration issue

When I take a close look at the output bundle in a boilerplate react-scripts 5 application, I see this in the minified source where it's supposed to require @headlessui/react:

      64237: function (e, t, r) {
        "use strict";
        e.exports = r.p + "static/media/index.439e41c35f66883d8abc.cjs"; <- hmmmm???
      },

And I can see in the build folder there's indeed a media folder with that file in it that is the headless ui code, but it's not putting the code inside the bundle

Now, I've figured out that if I remove these lines from the package.json of @headlessui/react, react-scripts 5 will bundle everything successfully:

  // need to remove all of these
  "exports": {
    "types": "./dist/index.d.ts",
    "require": "./dist/index.cjs",
    "import": "./dist/headlessui.esm.js"
  },

Which makes me thing I might be able to get around it by changing webpack's config somehow using craco, but I'm not exactly sure how

Is there a webpack configuration I can provide to get webpack to ignore the exports portion of the package.json?

0

1 Answer 1

0

This was due to an unsupported feature in create-react-app

cjs files were loaded via webpack as static assets instead of code

The bug and a workaround fix is outlined in the github issue:

https://github.com/facebook/create-react-app/issues/11889

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.