From 255484e677711e17433dea2a68b97d450c8f29fe Mon Sep 17 00:00:00 2001 From: Shu Ding Date: Fri, 8 Apr 2022 12:53:02 +0200 Subject: [PATCH] Use eager import to include client modules (#35979) Eager import does almost the same thing as `require()` but it instead also supports loading an ES module. ## Bug - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Errors have helpful link attached, see `contributing.md` ## Feature - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. - [ ] Errors have helpful link attached, see `contributing.md` ## Documentation / Examples - [ ] Make sure the linting passes by running `yarn lint` --- .../build/webpack/loaders/next-flight-server-loader.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/next/build/webpack/loaders/next-flight-server-loader.ts b/packages/next/build/webpack/loaders/next-flight-server-loader.ts index b3146902f79f..0419079a76f7 100644 --- a/packages/next/build/webpack/loaders/next-flight-server-loader.ts +++ b/packages/next/build/webpack/loaders/next-flight-server-loader.ts @@ -238,7 +238,12 @@ export default async function transformSource( __webpack_require__, _: () => { ${imports - .map((importSource) => `require('${importSource}');`) + .map( + (importSource) => + `import(/* webpackMode: "eager" */ ${JSON.stringify( + importSource + )});` + ) .join('\n')} }, server: ${isServerExt ? 'true' : 'false'}