Skip to content

Commit 159a832

Browse files
committed
Work around issue with next externals
1 parent d5bf7bc commit 159a832

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

@app/client/src/next.config.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,27 @@ if (!ROOT_URL) {
4141
webpack(config, { webpack, dev, isServer }) {
4242
if (dev) config.devtool = "cheap-module-source-map";
4343

44+
const makeSafe = externals => {
45+
if (Array.isArray(externals)) {
46+
return externals.map(ext => {
47+
if (typeof ext === "function") {
48+
return (context, request, callback) => {
49+
if (/^@app\//.test(request)) {
50+
callback();
51+
} else {
52+
return ext(context, request, callback);
53+
}
54+
};
55+
} else {
56+
return ext;
57+
}
58+
});
59+
}
60+
};
61+
62+
const externals =
63+
isServer && dev ? makeSafe(config.externals) : config.externals;
64+
4465
return {
4566
...config,
4667
plugins: [
@@ -51,7 +72,7 @@ if (!ROOT_URL) {
5172
}),
5273
],
5374
externals: [
54-
...(config.externals || []),
75+
...(externals || []),
5576
isServer ? { "pg-native": "pg/lib/client" } : null,
5677
].filter(_ => _),
5778
};

0 commit comments

Comments
 (0)