Skip to content

Commit 788e8c0

Browse files
quantizorclaude
andcommitted
fix: revert exports field and restore browser/server build split
The exports field caused TS2742 in composite projects and confused bundler resolution. The browser field + build-time __SERVER__ constant correctly dead-code-eliminates SSR paths (including require('stream')) in browser builds. Co-Authored-By: Claude Opus 4.6 <[email protected]>
1 parent a2cd792 commit 788e8c0

3 files changed

Lines changed: 12 additions & 35 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'styled-components': patch
3+
---
4+
5+
Revert `exports` field and restore browser/server build split with `browser` field in package.json. Fixes `require('stream')` resolution errors in browser bundlers like webpack 5.

‎packages/styled-components/package.json‎

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,6 @@
1313
"./dist/styled-components.cjs.js": "./dist/styled-components.browser.cjs.js",
1414
"./dist/styled-components.esm.js": "./dist/styled-components.browser.esm.js"
1515
},
16-
"exports": {
17-
".": {
18-
"react-native": {
19-
"types": "./native/dist/native/index.d.ts",
20-
"import": "./native/dist/styled-components.native.esm.js",
21-
"require": "./native/dist/styled-components.native.cjs.js",
22-
"default": "./native/dist/styled-components.native.cjs.js"
23-
},
24-
"types": "./dist/index.d.ts",
25-
"browser": {
26-
"import": "./dist/styled-components.browser.esm.js",
27-
"require": "./dist/styled-components.browser.cjs.js"
28-
},
29-
"import": "./dist/styled-components.esm.js",
30-
"require": "./dist/styled-components.cjs.js",
31-
"default": "./dist/styled-components.cjs.js"
32-
},
33-
"./native": {
34-
"types": "./native/dist/native/index.d.ts",
35-
"import": "./native/dist/styled-components.native.esm.js",
36-
"require": "./native/dist/styled-components.native.cjs.js",
37-
"default": "./native/dist/styled-components.native.cjs.js"
38-
},
39-
"./package.json": "./package.json"
40-
},
4116
"sideEffects": false,
4217
"scripts": {
4318
"generateErrors": "node scripts/generateErrorMap.js",
@@ -155,7 +130,7 @@
155130
"files": [
156131
{
157132
"path": "./dist/styled-components.min.js",
158-
"maxSize": "12kB"
133+
"maxSize": "12.3kB"
159134
}
160135
]
161136
},

‎packages/styled-components/src/models/ServerStyleSheet.tsx‎

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import React from 'react';
22
import { type PipeableStream } from 'react-dom/server';
3-
import type * as streamInternal from 'stream';
4-
import { IS_BROWSER, SC_ATTR, SC_ATTR_VERSION, SC_VERSION } from '../constants';
3+
import { SC_ATTR, SC_ATTR_VERSION, SC_VERSION } from '../constants';
54
import StyleSheet from '../sheet';
65
import styledError from '../utils/error';
6+
7+
declare const __SERVER__: boolean;
78
import { joinStringArray } from '../utils/joinStrings';
89
import getNonce from '../utils/nonce';
910
import { StyleSheetManager } from './StyleSheetManager';
1011

11-
declare const __SERVER__: boolean;
12-
1312
const CLOSING_TAG_R = /^\s*<\/[a-z]/i;
1413

1514
export default class ServerStyleSheet {
@@ -76,10 +75,8 @@ export default class ServerStyleSheet {
7675
return [<style {...props} key="sc-0-0" />];
7776
};
7877

79-
interleaveWithNodeStream(
80-
input: NodeJS.ReadableStream | PipeableStream
81-
): streamInternal.Transform {
82-
if (!__SERVER__ || IS_BROWSER) {
78+
interleaveWithNodeStream(input: NodeJS.ReadableStream | PipeableStream): NodeJS.ReadWriteStream {
79+
if (!__SERVER__) {
8380
throw styledError(3);
8481
} else if (this.sealed) {
8582
throw styledError(2);
@@ -90,7 +87,7 @@ export default class ServerStyleSheet {
9087
const { Transform } = require('stream');
9188
const { instance: sheet, _emitSheetCSS } = this;
9289

93-
const transformer: streamInternal.Transform = new Transform({
90+
const transformer: NodeJS.ReadWriteStream = new Transform({
9491
transform: function appendStyleChunks(
9592
chunk: string,
9693
/* encoding */

0 commit comments

Comments
 (0)