fix(build): emit import attributes with the with key - #4520
Conversation
|
@agantelin is attempting to deploy a commit to the Nitro Team on Vercel. A member of the Team first needs to authorize it. |
📝 WalkthroughWalkthroughRollup output configuration now sets ChangesImport attributes configuration
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related issues
Possibly related PRs
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
🧪 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.
🧹 Nitpick comments (2)
src/build/rollup/config.ts (1)
61-62: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winRemove the added explanatory source comments.
Both changed source segments explain compatibility details for a configuration line. Remove these comments or move the rationale to documentation.
src/build/rollup/config.ts#L61-L62: remove the two-line comment.src/build/vite/bundler.ts#L100-L100: remove the duplicate comment.As per coding guidelines: “Do not add comments explaining what the line does unless prompted.”
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/build/rollup/config.ts` around lines 61 - 62, Remove the two-line explanatory comment at src/build/rollup/config.ts lines 61-62 and the duplicate comment at src/build/vite/bundler.ts line 100, leaving the associated configuration lines unchanged.Source: Coding guidelines
test/unit/import-attributes.test.ts (1)
9-14: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick winCover both configuration paths and the override contract.
This test invokes
getRollupConfigonly. It does not exercise the Rollup branch ofsrc/build/vite/bundler.ts(Line 70-106) or verify that an explicitimportAttributesKey: "assert"remains unchanged. Add default and override cases for both builders.Based on PR objectives: the change covers both the Rollup builder and the Vite Rollup branch while preserving user overrides.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@test/unit/import-attributes.test.ts` around lines 9 - 14, Expand the import-attributes tests around getRollupConfig and the Rollup branch in bundler.ts to cover both builders: verify each defaults importAttributesKey to "with", and verify an explicit "assert" configuration remains unchanged for each path. Reuse the existing Nitro/Vite setup and preserve the current default assertion.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/build/rollup/config.ts`:
- Around line 61-62: Remove the two-line explanatory comment at
src/build/rollup/config.ts lines 61-62 and the duplicate comment at
src/build/vite/bundler.ts line 100, leaving the associated configuration lines
unchanged.
In `@test/unit/import-attributes.test.ts`:
- Around line 9-14: Expand the import-attributes tests around getRollupConfig
and the Rollup branch in bundler.ts to cover both builders: verify each defaults
importAttributesKey to "with", and verify an explicit "assert" configuration
remains unchanged for each path. Reuse the existing Nitro/Vite setup and
preserve the current default assertion.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: d68b8388-75d2-46b7-96cf-1df50ca62b85
📒 Files selected for processing (3)
src/build/rollup/config.tssrc/build/vite/bundler.tstest/unit/import-attributes.test.ts
fb8c898 to
e4c32a5
Compare
|
Pushed an update (force-push, same two source lines):
Nothing else changed. Still unverified on my side: an actual vite build, which doesn't start on |
🔗 Linked issue
#4518
❓ Type of change
📚 Description
Rollup 4 re-prints the import attributes of external modules with its default key,
assert, whichNode.js removed in 22.0.0 (nodejs/node#52104). Rollup itself flips the default in v5
(rollup/rollup#6248, merged to
rollup-5), and documentsoutput.importAttributesKeyas theworkaround until then; no 5.x is published.
This only bites the rollup paths — the default rolldown builder emits
withalready — so it'sbuilder: "rollup"and the rollup branch of the vite builder:src/build/rollup/config.ts— the default in the builder's output config; it sits in the objectdefumerges undernitro.options.rollupConfig, so user config still wins.src/build/vite/bundler.ts— same default, applied with??=after the merge, because in thatbranch
commonConfigis merged last and a literal would outrank user config.Symptom: the build is green, the server starts, and the route that imports the module answers 500
with
TypeError [ERR_IMPORT_ATTRIBUTE_MISSING]. I hit it through@nuxt/icon'sserverBundle.externalizeIconsJson, which generates a correctwith { type: "json" }import.Setting the key costs nothing on the supported matrix: the runtimes that take
assertbut rejectwithare all belowengines.node.📝 Checklist
importAttributesKeyisn't documented; afterthis the assets docs from feat(build): support
bytesandtextimport attributes #4431 describe what actually ships on the rollup path too.Verification
test/unit/import-attributes.test.tscovers three things, each checked by reverting thecorresponding line one at a time: the rollup builder's default, the vite builder's rollup branch,
and that an explicit
rollupConfig.output.importAttributesKeyfrom user config survives both.nitro@3.0.260610-betawithbuilder: "rollup":assert→ HTTP 500ERR_IMPORT_ATTRIBUTE_MISSING,with→ 200. Case 4 inhttps://github.com/agantelin/nitro-import-attributes-repro
test/fixture/regression route can't express this: the case needs an external JSON import,which the worker and edge presets can't load, so the fixture suite would fail for other reasons.
builder: "vite"doesn't get that faron Windows for me (
ERR_UNSUPPORTED_ESM_URL_SCHEME … Received protocol 'c:', unrelated to thischange, but you may want to know). The emitted config is pinned by the test above.