-
Notifications
You must be signed in to change notification settings - Fork 27.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable externalHelpers
when pre compiling Next.js' code
#37164
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1c47f4f
chore: enable `externalHelpers` for pre-compile
SukkaW bf228dd
chore(devDeps): update @swc/[email protected]
SukkaW e0ffd8b
Merge branch 'canary' into external-helper-build
SukkaW 90f359d
Merge branch 'canary' into external-helper-build
kodiakhq[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,14 +25,15 @@ module.exports = function (task) { | |
|
||
const isClient = serverOrClient === 'client' | ||
|
||
/** @type {import('@swc/core').Options} */ | ||
const swcClientOptions = { | ||
module: { | ||
type: 'commonjs', | ||
ignoreDynamic: true, | ||
}, | ||
jsc: { | ||
loose: true, | ||
|
||
externalHelpers: true, | ||
target: 'es2016', | ||
parser: { | ||
syntax: 'typescript', | ||
|
@@ -55,6 +56,7 @@ module.exports = function (task) { | |
}, | ||
} | ||
|
||
/** @type {import('@swc/core').Options} */ | ||
const swcServerOptions = { | ||
module: { | ||
type: 'commonjs', | ||
|
@@ -67,7 +69,9 @@ module.exports = function (task) { | |
}, | ||
jsc: { | ||
loose: true, | ||
|
||
// Do not enable externalHelpers for server-side code | ||
// "_is_native_function.mjs" helper is not compatible with edge runtime | ||
externalHelpers: false, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems this is also an issue with the client x-ref: #37829 |
||
parser: { | ||
syntax: 'typescript', | ||
dynamicImport: true, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we could use the
next-swc
binary here for transforming instead of installing@swc/core
as well, this could help us ensure we're matching behavior as this is already enabled there.This would also allow us to remove
@swc/core
as a dependency of the monorepoThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good idea. It also helps eliminate the inconsistency. Let me see what I can do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ijjk I have tried to re-use the file
next/build/swc/index.js
, but the file is dependent on the precompiled@napi-rs/triple
.Maybe it could be done in another PR? Where the shared logic can be extracted into
@next/swc
package.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could potentially expose an env variable to signal it should use the direct module instead of the compiled one e.g.
if (process.env.__NEXT_TASKR) { require('@napi-rs/triple') }
Yeah we can definitely investigate this in a separate PR