Skip to content

fix: silent IMPORT_IS_UNDEFINED for proxy.ts#787

Open
hyoban wants to merge 1 commit intocloudflare:mainfrom
hyoban:4-7-IMPORT_IS_UNDEFINED
Open

fix: silent IMPORT_IS_UNDEFINED for proxy.ts#787
hyoban wants to merge 1 commit intocloudflare:mainfrom
hyoban:4-7-IMPORT_IS_UNDEFINED

Conversation

@hyoban
Copy link
Copy Markdown
Contributor

@hyoban hyoban commented Apr 7, 2026

[IMPORT_IS_UNDEFINED] Warning: Import `default` will always be undefined because there is no matching export in 'proxy.ts'
      ╭─[ \0virtual:vinext-rsc-entry:2632:34 ]
      │
 2632 │     ? (middlewareModule.proxy ?? middlewareModule.default)
      │                                  ────────────┬───────────  
      │                                              ╰───────────── 
──────╯

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Apr 7, 2026

Open in StackBlitz

npm i https://pkg.pr.new/vinext@787

commit: c760b3b

@james-elicx
Copy link
Copy Markdown
Collaborator

/bigbonk review

Copy link
Copy Markdown
Contributor

@ask-bonk ask-bonk bot left a comment

Choose a reason for hiding this comment

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

Good fix for a real annoyance. The approach is correct — suppressing bundler noise for known-safe generated patterns. Two issues worth addressing:

  1. Missing .tsx/.jsx extensionsfindMiddlewareFile() iterates all pageExtensions (default: tsx, ts, jsx, js), so a user with proxy.tsx or middleware.jsx would still see the warning. The filter should cover all possible extensions, or match more broadly.

  2. Named export warnings not covered — The generated entry code does middlewareModule.proxy ?? middlewareModule.default (or .middleware ?? .default). When a file only exports default, the bundler can also warn about Import \proxy` will always be undefined(and vice versa). The current filter only matchesImport `default``, missing the symmetric case.

(warning.message?.includes("proxy.ts") ||
warning.message?.includes("proxy.js") ||
warning.message?.includes("middleware.ts") ||
warning.message?.includes("middleware.js")) &&
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This only covers .ts and .js, but findMiddlewareFile() iterates all fileMatcher.dottedExtensions which defaults to [".tsx", ".ts", ".jsx", ".js"] (and can include custom extensions via pageExtensions config). A user with proxy.tsx or middleware.jsx would still see the warning.

Consider matching on just the basename without extension, e.g.:

Suggested change
warning.message?.includes("middleware.js")) &&
if (
warning.code === "IMPORT_IS_UNDEFINED" &&
(warning.message?.includes("virtual:vinext-rsc-entry") ||
warning.message?.includes("virtual:vinext-server-entry")) &&
/Import `(?:default|proxy|middleware)` will always be undefined/.test(
warning.message ?? "",
) &&
/\b(?:proxy|middleware)\.\w+/.test(warning.message ?? "")
) {

This also covers the symmetric case where the named export (proxy or middleware) triggers the warning instead of default (e.g., when the file only has a default export, middlewareModule.proxy is undefined).

{
code: "IMPORT_IS_UNDEFINED",
message:
"[IMPORT_IS_UNDEFINED] Warning: Import `default` will always be undefined because there is no matching export in 'proxy.ts'\\n ╭─[ \\0virtual:vinext-rsc-entry:2632:34 ]",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The test message strings use \\n (literal backslash-n) instead of \n (actual newline). In real Rolldown output the message would contain an actual newline character. This doesn't affect correctness since .includes() would match either way in this test, but it's slightly misleading.

Also, consider adding test cases for:

  • .tsx/.jsx extensions (proxy.tsx, middleware.jsx)
  • Named export warnings (Import \proxy` will always be undefined`)
  • The symmetric case where only a default export exists

@ask-bonk
Copy link
Copy Markdown
Contributor

ask-bonk bot commented Apr 7, 2026

Review posted successfully. Here's a summary of the feedback:

PR #787 suppresses noisy IMPORT_IS_UNDEFINED warnings for proxy.ts/middleware.ts default export fallbacks in generated virtual entries. The fix is correct in approach, but has two gaps:

  1. Missing .tsx/.jsx extensions — The filter only matches .ts and .js, but findMiddlewareFile() scans all pageExtensions (default: tsx, ts, jsx, js). Users with proxy.tsx or middleware.jsx would still see the warning. Suggested using a regex like /\b(?:proxy|middleware)\.\w+/ to match any extension.

  2. Named export warnings not covered — The generated code does middlewareModule.proxy ?? middlewareModule.default. When a file only has a default export, the bundler can also warn about Import \proxy` will always be undefined(the symmetric case). The current filter only matchesImport `default`. Suggested broadening to match Import `(?:default|proxy|middleware)``.

github run

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.

2 participants