Skip to content

Add exports to package.json - #5644

Merged
quantizor merged 3 commits into
styled-components:mainfrom
coolassassin:patch-1
Jan 16, 2026
Merged

quantizor merged 3 commits into
styled-components:mainfrom
coolassassin:patch-1

Conversation

@coolassassin

@coolassassin coolassassin commented Jan 15, 2026 •

Copy link
Copy Markdown
Contributor

Hello!

I am trying to move on ESM modules in my project and on Vitest and I have started to catch errors like so:

TypeError: styled.div is not a function

I have this issue when I use this kind of import:

import styled from 'styled-components'

While I am writing my application over bundlers all works fine, because every bundler goes to package.json and takes "module" instruction from there.
But when I use vitest and it sees package which is marked as "type": "module" it tries to resolve it with a Node.js module way
By the Node.js module resolution it tries to read "exports" and if there is no information it goes to the "main" field. And there is "cjs" as you can see

Here is a scheme:

Bundler(App) -> package.json(any) -> "module" ✅
Vitest(Node.js) -> package.json(without "type": "module") -> "main(cjs)" ✅
Vitest(Node.js) -> package.json("type": "module") -> "main(cjs)" ❌

With export it will work like so:

Bundler(App) -> package.json(any) -> "module" ✅
Vitest(Node.js) -> package.json(without "type": "module") -> "exports.require(cjs)" ✅
Vitest(Node.js) -> package.json("type": "module") -> "exports.import(esm)" ✅

Note

Improves Node/ESM resolution by defining an explicit exports map for styled-components.

  • Adds exports in packages/styled-components/package.json covering . and ./native with import (ESM), require (CJS), browser, react-native, and types, plus ./package.json
  • Ensures correct entry selection across bundlers, Node/Vitest, browser, and React Native
  • Adds a changeset marking a patch release

Written by Cursor Bugbot for commit 7f22eb0. This will update automatically on new commits. Configure here.

@changeset-bot

changeset-bot Bot commented Jan 15, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 7f22eb0

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
styled-components Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@quantizor quantizor left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

This PR is being reviewed by Cursor Bugbot

Details

You are on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle.

To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

Comment thread packages/styled-components/package.json Resolved
@quantizor
quantizor merged commit 1f794b7 into styled-components:main Jan 16, 2026
@coolassassin

Copy link
Copy Markdown
Contributor Author

@quantizor
788e8c0
Can you tell me why it was reverted? It is neccessary changes.
Can I remake it somehow to do it right?

@quantizor

quantizor commented Feb 10, 2026 •

Copy link
Copy Markdown
Contributor

@quantizor 788e8c0 Can you tell me why it was reverted? It is neccessary changes. Can I remake it somehow to do it right?

It broke a bunch of stuff unfortunately and caused issues like multiple versions of the library being loaded, type visibility problems for composite projects, etc. There's probably a different way to fix it.

@quantizor

Copy link
Copy Markdown
Contributor

We can change the main field to the ESM bundle in the next major. We're probably due for one soon.

@coolassassin

Copy link
Copy Markdown
Contributor Author

@quantizor can I reproduce these bugs somehow? Maybe I can add some tests
I need this fix 😔

@coolassassin

Copy link
Copy Markdown
Contributor Author

I have opened this PR:
#5662

There, I have mentioned the issue withthe composite projects has appeared before my change

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants