Skip to content

SWC plugin runner no longer provides full file path to metadata #72019

@serg-and

Description

@serg-and

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())

Metadata

Metadata

Assignees

No one assigned

    Labels

    Pages RouterRelated to Pages Router.SWCRelated to minification/transpilation in Next.js.linear: nextConfirmed issue that is tracked by the Next.js team.locked

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions