Skip to content

fix(node-protocol): respect alias and tsconfig paths when stripping node: prefix#773

Merged
sxzz merged 4 commits intorolldown:mainfrom
lazuee:main
Feb 26, 2026
Merged

fix(node-protocol): respect alias and tsconfig paths when stripping node: prefix#773
sxzz merged 4 commits intorolldown:mainfrom
lazuee:main

Conversation

@lazuee
Copy link
Contributor

@lazuee lazuee commented Feb 19, 2026

Description

When nodeProtocol: "strip" is configured, the NodeProtocolPlugin runs with order: 'pre' and immediately marks stripped node: imports as external: true. This short-circuits the entire resolution chain, so alias and tsconfig paths configurations that map the stripped module name (e.g., crypto) to a polyfill are never consulted.

The fix changes the strip handler to call this.resolve() with the stripped ID before marking it as external. If another resolver (alias, tsconfig paths) resolves it to a non-external module, that resolution is used instead.

Linked Issues

Fixes #772

Additional context

The test covers both resolution methods in a single case:

  • alias: node:path → stripped to path → resolved via alias to a polyfill
  • tsconfig paths: node:crypto → stripped to crypto → resolved via paths to a polyfill

@netlify
Copy link

netlify bot commented Feb 19, 2026

Deploy Preview for tsdown-main ready!

Name Link
🔨 Latest commit c8aa040
🔍 Latest deploy log https://app.netlify.com/projects/tsdown-main/deploys/6999e6262131e90008347df1
😎 Deploy Preview https://deploy-preview-773--tsdown-main.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 19, 2026

Open in StackBlitz

tsdown

pnpm add https://pkg.pr.new/tsdown@773 -D
npm i https://pkg.pr.new/tsdown@773 -D
yarn add https://pkg.pr.new/tsdown@773.tgz -D

create-tsdown

pnpm add https://pkg.pr.new/create-tsdown@773 -D
npm i https://pkg.pr.new/create-tsdown@773 -D
yarn add https://pkg.pr.new/create-tsdown@773.tgz -D

tsdown-migrate

pnpm add https://pkg.pr.new/tsdown-migrate@773 -D
npm i https://pkg.pr.new/tsdown-migrate@773 -D
yarn add https://pkg.pr.new/tsdown-migrate@773.tgz -D

commit: c8aa040

@lazuee
Copy link
Contributor Author

lazuee commented Feb 21, 2026

Using https://pkg.pr.new/tsdown@773 with an alias, this.resolve() returns null unexpectedly,
tsconfig paths works as expected tho,. And also doing pnpm test with this PR, test#772 works as expected.

Idk, why this.resolve() returns null when using alias 🤔
https://github.com/lazuee-dev/repro-tsdown-paths-nodeProtocol-strip

@sxzz sxzz merged commit b1dd232 into rolldown:main Feb 26, 2026
16 checks passed
@sxzz
Copy link
Member

sxzz commented Feb 27, 2026

@lazuee Your alias option is incorrect:

alias: {
	"crypto": "./src/crypto-polyfill.ts",
},
// src/index.ts
import 'crypto'
// rewrite to
import './src/crypto-polyfill.ts' // which redirect to src/src/crypto-polyfill.ts

You can use absolute path or change it to ./crypto-polyfill.ts.

@lazuee
Copy link
Contributor Author

lazuee commented Feb 27, 2026

@sxzz It works, but why does the relative path ./src/crypto-polyfill.ts resolve to src/src/crypto-polyfill.ts? Is the alias root directory based on the current directory of the entry file, not on the root directory?

on the rolldown#resolve.alias it seems it based on the root directory.

@sxzz
Copy link
Member

sxzz commented Feb 27, 2026

It's by design in Rolldown.

resolve.alias will not call resolveId hooks of other plugin. If you want to call resolveId hooks of other plugin, use viteAliasPlugin from rolldown/experimental instead. You could find more discussion in this issue

https://repl.rolldown.rs/#eNptUb1qwzAQfpVDi1twnN3QqaXQpVs2L4p1TgTyyUinNMH43aufJLhpwFjS3X0/+jSLQbSzcNYYZX+o6S0N+tCwT1US7bNOLfrY0ONkHcMMCgdN+J7bsMDg7AjVDVZ11BGe82gclMHk9Q54mTsC0DQFbqFQNiOybHKphu0W+IgwaIMePBrsGRXsL7m6D8yWIH4o+yOw3CeyyUgerBtbqMgqrOpUdOitOWELWQ9AGi39/QTQu8vENkKabdluJmsuUdbEGxeKhzHv+qejyfK3Zfi0gVTBLRmf/strR2KpRQJrUnheJf2n9pCxk6TsuNt9fdwTLtrrfOMLeQat4G01/5IUa4GiZRfwKv3f99rEk26xc9UZAvWsY+prlRY8O02HEqlDDo6gunFsQtAqel3S9aOJU2SLz4SexfIL+MHcaA==

@lazuee
Copy link
Contributor Author

lazuee commented Feb 27, 2026

I see, thanks for the info!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

nodeProtocol: "strip" ignores paths resolution for stripped node: imports

2 participants