fix(tsgo): do not error out on non js/ts imports from npm packages#31478
fix(tsgo): do not error out on non js/ts imports from npm packages#31478nathanwhit merged 2 commits intodenoland:mainfrom
Conversation
WalkthroughThe PR makes two main changes. In cli/tsc/go.rs, an early filtering step is added to load_inner that classifies media types and skips non-JS/TS sources (SourceMap, Css, Jsonc, Json5, Html, Sql, Wasm, Unknown) by returning Ok(None), while preserving the existing flow for JS/TS sources. In tests/specs/check/css_import/exists.ts, an import of a CSS file from an npm module is added alongside the existing local CSS import. Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
cli/tsc/go.rs (1)
665-690: Early-return for non-JS/TS media types correctly avoids tsc parsingThe new
match media_typecleanly separates JS/TS(+JSON) from everything else and returningOk(None)for Css/Html/Sql/Wasm/SourceMap/Jsonc/Json5/Unknown is aligned with the goal of not letting tsc treat these as source files.One subtle behavior change to be aware of: when
load_innerreturnsNone,getImpliedNodeFormatForFilenow falls back toResolutionMode::ESM, whereas previously CSS (and other non-JS/TS) went throughget_resolution_modeand could end up withResolutionMode::None. That’s probably fine if TypeScript never consults node format for files we skip as source, but it is a semantic change.If you want to keep the old implied-format behavior while still skipping source creation, you could precompute and store
module_kindfor all media types, then early-return only for the non-JS/TS ones, for example:- let is_cjs = result.is_cjs; - let media_type = result.media_type; - - match media_type { + let is_cjs = result.is_cjs; + let media_type = result.media_type; + let module_kind = get_resolution_mode(is_cjs, media_type); + + match media_type { MediaType::JavaScript @@ - | MediaType::Unknown => return Ok(None), + | MediaType::Unknown => { + state + .module_kind_map + .insert(load_specifier.to_string(), module_kind); + return Ok(None); + } } - - let module_kind = get_resolution_mode(is_cjs, media_type); + // JS/TS-like: fall through and return LoadResult as beforeNot a blocker, but worth confirming this matches how tsgo expects
getImpliedNodeFormatForFileto behave.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
tests/specs/check/css_import/exists.outis excluded by!**/*.out
📒 Files selected for processing (2)
cli/tsc/go.rs(1 hunks)tests/specs/check/css_import/exists.ts(1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.rs
📄 CodeRabbit inference engine (CLAUDE.md)
**/*.rs: For debugging Rust code, set breakpoints in IDE debuggers (VS Code with rust-analyzer, IntelliJ IDEA) or uselldbdirectly
Useeprintln!()ordbg!()macros for debug prints in Rust code
Files:
cli/tsc/go.rs
**/*.{ts,tsx,js}
📄 CodeRabbit inference engine (CLAUDE.md)
**/*.{ts,tsx,js}: For JavaScript runtime debugging, enable V8 inspector with--inspect-brkflag and connect Chrome DevTools tochrome://inspect
Useconsole.log()for debug prints in JavaScript runtime code
Files:
tests/specs/check/css_import/exists.ts
🧠 Learnings (1)
📚 Learning: 2025-11-24T16:19:37.808Z
Learnt from: CR
Repo: denoland/deno PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-24T16:19:37.808Z
Learning: Applies to cli/module_loader.rs : Module loading and resolution is handled in `cli/module_loader.rs`
Applied to files:
cli/tsc/go.rs
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
- GitHub Check: test release linux-x86_64
- GitHub Check: test debug linux-x86_64
- GitHub Check: test debug linux-aarch64
- GitHub Check: test debug macos-aarch64
- GitHub Check: test debug windows-x86_64
- GitHub Check: test debug macos-x86_64
- GitHub Check: build libs
- GitHub Check: lint debug macos-x86_64
- GitHub Check: lint debug linux-x86_64
- GitHub Check: lint debug windows-x86_64
🔇 Additional comments (1)
tests/specs/check/css_import/exists.ts (1)
3-3: LGTM: npm CSS import exercises the intended scenarioThe added npm CSS import matches the PR’s goal (ensuring
deno checkdoesn’t error on non-JS/TS npm assets) and keeps the test simple and focused.
Fixes #31423
This already worked for non npm files because the loading for non-npm files uses the module graph, and things like CSS don't appear in the module graph. That meant we weren't prompting tsc to create a source file and parse those files. For npm files though, we were loading them manually, which meant tsc tried to load them as ts/js sources