-
Notifications
You must be signed in to change notification settings - Fork 29.4k
Description
Link to the code that reproduces this issue
https://github.com/serg-and/nextjs-minimal-swc-plugin-issue
To Reproduce
npm i
cd swc_plugin
npm run prepublish
cd ..
npm run dev
Logs will show that the provided filename in the metadata no longer includes the file path, only the filename.
Current vs. Expected behavior
Next's pluggin runner no longer provides the known file path to the metadata for a SWC plugin, only providing the file name.
This is conflict with SWC, saying: swc docs
/// Host side metadata context plugin may need to access.
/// This is a global context - any plugin in single transform will have same
/// values.
pub struct TransformPluginMetadataContext {
/// The path of the file being processed. This includes all of the path as
/// much as possible.
pub filename: Option<String>,
...
}
This breaks several packages such as next-superjson-plugin which rely on the path to determine whether some files are page or app router based.
Provide environment information
Operating System:
Platform: linux
Arch: arm64
Version: #1 SMP Wed Jul 17 10:51:09 UTC 2024
Available memory (MB): 7185
Available CPU cores: 8
Binaries:
Node: 20.11.1
npm: 10.2.4
Yarn: 1.22.19
pnpm: N/A
Relevant Packages:
next: 15.0.1 // Latest available version is detected (15.0.1).
eslint-config-next: 15.0.1
react: 18.3.1
react-dom: 18.3.1
typescript: 5.0.4
Next.js Config:
output: N/A
Which area(s) are affected? (Select all that apply)
Pages Router, SWC
Which stage(s) are affected? (Select all that apply)
next dev (local)
Additional context
I believe the issue originates from here https://github.com/vercel/next.js/blob/v15.0.1/turbopack/crates/turbopack-ecmascript-plugins/src/transform/swc_ecma_transform_plugins.rs#L189
Some(ctx.file_name_str.to_string())
could simply be changed to Some(ctx.file_path_str.to_string())