Skip to content

Commit c3e880f

Browse files
committed
chore: enable externalHelpers for precompile client code
1 parent ccb155e commit c3e880f

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

packages/next/taskfile-swc.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,15 @@ module.exports = function (task) {
2525

2626
const isClient = serverOrClient === 'client'
2727

28+
/** @type {import('@swc/core').Options} */
2829
const swcClientOptions = {
2930
module: {
3031
type: 'commonjs',
3132
ignoreDynamic: true,
3233
},
3334
jsc: {
3435
loose: true,
35-
36+
externalHelpers: true,
3637
target: 'es2016',
3738
parser: {
3839
syntax: 'typescript',
@@ -55,6 +56,7 @@ module.exports = function (task) {
5556
},
5657
}
5758

59+
/** @type {import('@swc/core').Options} */
5860
const swcServerOptions = {
5961
module: {
6062
type: 'commonjs',
@@ -67,7 +69,9 @@ module.exports = function (task) {
6769
},
6870
jsc: {
6971
loose: true,
70-
72+
// Do not enable externalHelpers for server-side code
73+
// @swc/helpers/_is_native_function.js is not compatible with edge-runtime
74+
externalHelpers: false,
7175
parser: {
7276
syntax: 'typescript',
7377
dynamicImport: true,

packages/next/taskfile.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ const externals = {
6363

6464
'terser-webpack-plugin':
6565
'next/dist/build/webpack/plugins/terser-webpack-plugin',
66+
67+
/**
68+
* TODO: add @swc/helpers as once ncc replaces ts-loader
69+
* with swc-loader and externalHelpers becomes an option:
70+
* https://github.com/vercel/ncc/pull/926/
71+
*/
6672
}
6773
// eslint-disable-next-line camelcase
6874
externals['node-html-parser'] = 'next/dist/compiled/node-html-parser'
@@ -1956,7 +1962,7 @@ export async function shared(task, opts) {
19561962
.source(
19571963
opts.src || 'shared/**/!(amp|config|constants|dynamic|head).+(js|ts|tsx)'
19581964
)
1959-
.swc('server', { dev: opts.dev })
1965+
.swc('client', { dev: opts.dev })
19601966
.target('dist/shared')
19611967
notify('Compiled shared files')
19621968
}
@@ -1966,7 +1972,7 @@ export async function shared_re_exported(task, opts) {
19661972
.source(
19671973
opts.src || 'shared/**/{amp,config,constants,dynamic,head}.+(js|ts|tsx)'
19681974
)
1969-
.swc('server', { dev: opts.dev, interopClientDefaultExport: true })
1975+
.swc('client', { dev: opts.dev, interopClientDefaultExport: true })
19701976
.target('dist/shared')
19711977
notify('Compiled shared re-exported files')
19721978
}

0 commit comments

Comments
 (0)