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 22, 2023
1 parent e66332a commit bd68dd2
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 7 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
29 changes: 27 additions & 2 deletions scripts/rollup/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,31 @@ 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 modulesWithCommonJsExports = [
'JSResourceReferenceImpl',
'error-stack-parser',
'art/core/transform',
'art/modes/current',
'art/modes/fast-noSideEffects',
'art/modes/svg',
];

if (modulesWithCommonJsExports.includes(id)) {
return 'default';
}

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

function getRollupOutputOptions(
outputPath,
format,
Expand All @@ -187,7 +212,7 @@ function getRollupOutputOptions(
format,
globals,
freeze: !isProduction,
interop: false,
interop: getRollupInteropValue,
name: globalName,
sourcemap: false,
esModule: false,
Expand Down Expand Up @@ -612,7 +637,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
13 changes: 10 additions & 3 deletions scripts/rollup/wrappers.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,9 @@ if (process.env.NODE_ENV !== "production") {
${source}
return exports;
};
}`;
module.exports.default = module.exports;
}
`;
},

/***************** NODE_PROD (reconciler only) *****************/
Expand All @@ -366,10 +368,13 @@ ${source}
${license}
*/
module.exports = function $$$reconciler($$$hostConfig) {
var exports = {};
${source}
return exports;
};`;
};
module.exports.default = module.exports;
`;
},

/***************** NODE_PROFILING (reconciler only) *****************/
Expand All @@ -384,7 +389,9 @@ module.exports = function $$$reconciler($$$hostConfig) {
var exports = {};
${source}
return exports;
};`;
};
module.exports.default = module.exports;
`;
},
};

Expand Down

0 comments on commit bd68dd2

Please sign in to comment.