Skip to content

Commit

Permalink
Fix Rollup v3 build issues
Browse files Browse the repository at this point in the history
  • Loading branch information
markerikson committed Mar 20, 2023
1 parent e66332a commit be8a808
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/react-server-dom-webpack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"./server.node.unbundled": "./server.node.unbundled.js",
"./node-loader": "./esm/react-server-dom-webpack-node-loader.production.min.js",
"./node-register": "./node-register.js",
"./src/*": "./src/*",
"./src/*": "./src/*.js",
"./package.json": "./package.json"
},
"main": "index.js",
Expand Down
28 changes: 26 additions & 2 deletions scripts/rollup/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,30 @@ function getBabelConfig(
return options;
}

let getRollupInteropValue = id => {
// ReactNoop.js and ReactNoopPersistent.js use several default imports from other internal packages.
// That gets turned into a `require()`, but the `module.exports = function reconciler()` wrapper
// gets added later, so Rollup isn't fully aware of it, and tries to use `RFR.default` instead.
// Force Rollup to use the `require()`'d value directly, without adding a `.default`.
// Other cases:
// - `react-art` needs to deal with imports from the `art` package
// -`error-stack-parser`
const exactModuleNames = [
'react-reconciler',
'react-server/flight',
'react-client/flight',
'react-server',
'error-stack-parser',
];

if (exactModuleNames.includes(id) || id.startsWith('art/')) {
return 'default';
}

// For all other modules, handle imports without any import helper utils
return 'esModule';
};

function getRollupOutputOptions(
outputPath,
format,
Expand All @@ -187,7 +211,7 @@ function getRollupOutputOptions(
format,
globals,
freeze: !isProduction,
interop: false,
interop: getRollupInteropValue,
name: globalName,
sourcemap: false,
esModule: false,
Expand Down Expand Up @@ -612,7 +636,7 @@ async function createBundle(bundle, bundleType) {
output: {
externalLiveBindings: false,
freeze: false,
interop: false,
interop: getRollupInteropValue,
esModule: false,
},
};
Expand Down
2 changes: 1 addition & 1 deletion scripts/rollup/bundles.js
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ const bundles = [
{
bundleTypes: [NODE_ES2015],
moduleType: RENDERER_UTILS,
entry: 'react-server-dom-webpack/src/ReactFlightWebpackNodeRegister.js',
entry: 'react-server-dom-webpack/src/ReactFlightWebpackNodeRegister',
name: 'react-server-dom-webpack-node-register',
global: 'ReactFlightWebpackNodeRegister',
minifyWithProdErrorCodes: false,
Expand Down

0 comments on commit be8a808

Please sign in to comment.