Skip to content

Commit 0339874

Browse files
committed
fix: changing external dependencies in webpack as externalsType Module
An error was identified when using an external lib, webpack resolves it as dynamic import and to resolve this it was changed to use externalType module.
1 parent a7dffb0 commit 0339874

File tree

4 files changed

+44
-30
lines changed

4 files changed

+44
-30
lines changed

lib/build/bundlers/webpack/plugins/azion-polyfills/azion-polyfills.plugins.js

+27-15
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,20 @@ class AzionPolyfillPlugin {
1414
compiler.options.plugins = [];
1515
}
1616

17+
// additional plugin to handle "node:" URIs
18+
compiler.options.plugins.push(
19+
new compiler.webpack.NormalModuleReplacementPlugin(
20+
new RegExp(`^${this.prefix}`),
21+
(resource) => {
22+
const mod = resource.request.replace(
23+
new RegExp(`^${this.prefix}`),
24+
'',
25+
);
26+
resource.request = mod;
27+
},
28+
),
29+
);
30+
1731
const filteredExternal = new Map(
1832
[...polyfillsManager.external].filter(([key]) => {
1933
const hasPrefix = new RegExp(`^${this.prefix}`).test(key);
@@ -22,21 +36,19 @@ class AzionPolyfillPlugin {
2236
);
2337

2438
if (this.buildProd) {
25-
compiler.options.externals = compiler.options.externals || [];
26-
compiler.options.externals.push(
27-
// eslint-disable-next-line
28-
({ request }, callback) => {
29-
const externalsToCheck = [...filteredExternal.keys()];
30-
31-
if (
32-
externalsToCheck.some((key) => new RegExp(`${key}$`).test(request))
33-
) {
34-
return callback(null, `module ${request}`);
35-
}
36-
37-
return callback();
38-
},
39-
);
39+
compiler.options.externals = compiler.options.externals || {};
40+
compiler.options.externalsType = 'module';
41+
compiler.options.externals = {
42+
...Object.fromEntries(
43+
[...filteredExternal].flatMap(([key]) => {
44+
return [
45+
[key, key],
46+
[`${this.prefix}${key}`, `${this.prefix}${key}`],
47+
];
48+
}),
49+
),
50+
...compiler.options.externals,
51+
};
4052
} else {
4153
compiler.options.plugins.push(
4254
new compiler.webpack.NormalModuleReplacementPlugin(

lib/build/bundlers/webpack/plugins/node-polyfills/node-polyfills.plugins.js

+13-15
Original file line numberDiff line numberDiff line change
@@ -63,21 +63,19 @@ class NodePolyfillPlugin {
6363
);
6464

6565
if (this.buildProd) {
66-
compiler.options.externals = compiler.options.externals || [];
67-
compiler.options.externals.push(
68-
// eslint-disable-next-line
69-
({ request }, callback) => {
70-
const externalsToCheck = [...filteredExternal.keys()];
71-
72-
if (
73-
externalsToCheck.some((key) => new RegExp(`${key}$`).test(request))
74-
) {
75-
return callback(null, `module ${request}`);
76-
}
77-
78-
return callback();
79-
},
80-
);
66+
compiler.options.externals = compiler.options.externals || {};
67+
compiler.options.externalsType = 'module';
68+
compiler.options.externals = {
69+
...compiler.options.externals,
70+
...Object.fromEntries(
71+
[...filteredExternal].flatMap(([key]) => {
72+
return [
73+
[key, key],
74+
[`${this.prefix}${key}`, `${this.prefix}${key}`],
75+
];
76+
}),
77+
),
78+
};
8179
} else {
8280
compiler.options.resolve.fallback = {
8381
...Object.fromEntries(

lib/build/bundlers/webpack/webpack.config.js

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ const outputPath = isWindows
1212
: join(projectRoot, '.edge');
1313

1414
export default {
15+
experiments: {
16+
outputModule: true,
17+
},
1518
output: {
1619
path: outputPath,
1720
filename: 'worker.js',

lib/presets/custom/next/compute/default/prebuild/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ async function run(prebuildContext) {
124124
// this is necessary in the order of use, which needs to be defined at the top of the worker
125125
_ENTRIES: JSON.stringify({}),
126126
__CONFIG__: JSON.stringify(processedVercelOutput.vercelConfig),
127+
AsyncLocalStorage: JSON.stringify({}),
127128
},
128129
builderPlugins: [],
129130
};

0 commit comments

Comments
 (0)