Thanks to visit codestin.com
Credit goes to github.com

Skip to content

SWC plugin context in Turbopack includes only basename instead of full path #78181

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

Closed
jantimon opened this issue Apr 15, 2025 · 2 comments · Fixed by #78637
Closed

SWC plugin context in Turbopack includes only basename instead of full path #78181

jantimon opened this issue Apr 15, 2025 · 2 comments · Fixed by #78637
Labels
linear: turbopack Confirmed issue that is tracked by the Turbopack team. Turbopack Related to Turbopack with Next.js.

Comments

@jantimon
Copy link
Contributor

Link to the code that reproduces this issue

https://github.com/DigitecGalaxus/next-yak/tree/turbopack-plugin-syntax

To Reproduce

Currently the reproduction is only available on a branch which works around the fact that turbopack is not able to work with absolut paths (see issue #78156) - Please let me know if it's still okay

  1. Clone the repository: git clone https://github.com/DigitecGalaxus/next-yak/ -b turbopack-plugin-syntax
  2. Install dependencies: pnpm i
  3. Build the project: pnpm run build && pnpm run build:swc
  4. Navigate to example: cd packages/example
  5. Run build with turbopack: npx next build --turbopack

You'll see errors like:

thread 'thread '<unnamed><unnamed>' panicked at ' panicked at relative_posix_path/src/lib.rsrelative_posix_path/src/lib.rs::1717::59:
59: Could not create relative pathCould not create relative path

Processing file: layout.tsx

Debug info:
- Execution of TaskId { id: 2147483651 } transient failed
- Execution of get_all_written_entrypoints_with_issues_operation failed
- Execution of EntrypointsOperation::new failed
- Execution of all_entrypoints_write_to_disk_operation failed
- Execution of Project::emit_all_output_assets failed
- Execution of all_assets_from_entries_operation failed
- Execution of output_assets_operation failed
- Execution of <PageEndpoint as Endpoint>::output failed
- Failed to write page endpoint /_error
- Execution of PageEndpoint::output failed
- Execution of PageEndpoint::client_chunks failed
- Execution of Project::client_chunking_context failed
- Execution of Project::module_ids failed
- Execution of Project::whole_app_module_graphs failed
- Execution of whole_app_module_graph_operation failed
- Execution of Project::get_all_entries failed
- Execution of <AppEndpoint as Endpoint>::entries failed
- Execution of get_app_page_entry failed
- Execution of Transition::process failed
- Execution of apply_module_type failed
- Execution of <EcmascriptModuleAsset as EcmascriptChunkPlaceable>::get_exports failed
- Execution of analyse_ecmascript_module failed
- failed to analyse ecmascript module '[project]/packages/example/app/layout.tsx [app-rsc] (ecmascript)'
- Execution of parse failed
- failed to parse [project]/packages/example/app/layout.tsx
- Transforming and/or parsing of [project]/packages/example/app/layout.tsx failed

Current vs. Expected behavior

  • In Turbopack, metadata.get_context(&TransformPluginMetadataContextKind::Filename) returns only the basename (e.g., layout.tsx) without any directory information
  • This causes my plugin to crash as it can't generate consistent hashes based on just the basename

Expected behavior:

  • In Webpack, the same function returns the full absolute path (e.g., /full/path/to/app/layout.tsx)
  • Turbopack should return the same full path information to maintain plugin compatibility between build systems

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.3.0: Thu Jan  2 20:24:16 PST 2025; root:xnu-11215.81.4~3/RELEASE_ARM64_T6000
  Available memory (MB): 65536
  Available CPU cores: 10
Binaries:
  Node: 20.18.2
  npm: 10.8.2
  Yarn: 1.22.22
  pnpm: 9.12.3
Relevant Packages:
  next: 15.3.1-canary.8
  eslint-config-next: N/A
  react: 19.0.0
  react-dom: 19.0.0
  typescript: 5.7.2
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Turbopack

Which stage(s) are affected? (Select all that apply)

next build (local)

Additional context

We use the following rust code to read the filename from the context:

pub fn process_transform(program: Program, metadata: TransformPluginProgramMetadata) -> Program {
  let filename = metadata
    .get_context(&TransformPluginMetadataContextKind::Filename)
    .expect("failed to get filename");
  // Convert to consistent relative path...
}
@github-actions github-actions bot added the Turbopack Related to Turbopack with Next.js. label Apr 15, 2025
@mischnic mischnic added the linear: turbopack Confirmed issue that is tracked by the Turbopack team. label Apr 15, 2025
@mischnic
Copy link
Contributor

mischnic commented Apr 23, 2025

Sounds similar to #72019

@jantimon
Copy link
Contributor Author

@mischnic you are right this is a duplicate of #72019 - should I close it?

btw @serg-and proposed a possible fix: #72019 (comment) do you think we could use his approach?

kdy1 added a commit that referenced this issue Apr 30, 2025
### What?

Provide full path to the SWC Wasm plugins

### Why?

To align with other SWC Wasm plugin runtimes

### How?

 - Closes PACK-4363
 - Closes #78181
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
linear: turbopack Confirmed issue that is tracked by the Turbopack team. Turbopack Related to Turbopack with Next.js.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants