Skip to content

fix(tsgo): do not error out on non js/ts imports from npm packages#31478

Merged
nathanwhit merged 2 commits intodenoland:mainfrom
nathanwhit:nw-branch-9
Dec 2, 2025
Merged

fix(tsgo): do not error out on non js/ts imports from npm packages#31478
nathanwhit merged 2 commits intodenoland:mainfrom
nathanwhit:nw-branch-9

Conversation

@nathanwhit
Copy link
Copy Markdown
Member

@nathanwhit nathanwhit commented Dec 2, 2025

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

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Dec 2, 2025

Walkthrough

The 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)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: preventing errors when handling non-JS/TS imports from npm packages.
Description check ✅ Passed The description clearly explains the issue and solution, relating directly to the changeset.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 parsing

The new match media_type cleanly separates JS/TS(+JSON) from everything else and returning Ok(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_inner returns None, getImpliedNodeFormatForFile now falls back to ResolutionMode::ESM, whereas previously CSS (and other non-JS/TS) went through get_resolution_mode and could end up with ResolutionMode::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_kind for 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 before

Not a blocker, but worth confirming this matches how tsgo expects getImpliedNodeFormatForFile to behave.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0d662fe and d69a93b.

⛔ Files ignored due to path filters (1)
  • tests/specs/check/css_import/exists.out is 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 use lldb directly
Use eprintln!() or dbg!() 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-brk flag and connect Chrome DevTools to chrome://inspect
Use console.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 scenario

The added npm CSS import matches the PR’s goal (ensuring deno check doesn’t error on non-JS/TS npm assets) and keeps the test simple and focused.

@nathanwhit nathanwhit enabled auto-merge (squash) December 2, 2025 21:42
@nathanwhit nathanwhit merged commit 746f60d into denoland:main Dec 2, 2025
21 checks passed
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.

TSGO crashes with npm css import

2 participants