Skip to content

chore: avoid missing file extension warning in test/examples - #1775

Open
yamachi4416 wants to merge 4 commits into
nuxt:mainfrom
yamachi4416:fix-import-cjs
Open

chore: avoid missing file extension warning in test/examples#1775
yamachi4416 wants to merge 4 commits into
nuxt:mainfrom
yamachi4416:fix-import-cjs

Conversation

@yamachi4416

@yamachi4416 yamachi4416 commented Aug 8, 2026

Copy link
Copy Markdown
Member

🔗 Linked issue

📚 Description

Add test for cjs module adding to vite.optimizeDeps.include in nuxt.config.ts, and post a comment to a solution to the issue: #1388

avoid missing file extension warning

import "./app5/bare.vitest.config" without a file extension (vitest.config.ts:7:14). Add the file extension

ignore vitest test results in .gitignore

@pkg-pr-new

pkg-pr-new Bot commented Aug 8, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@nuxt/test-utils@1775
npm i https://pkg.pr.new/vitest-environment-nuxt@1775

commit: 38591c0

@yamachi4416 yamachi4416 changed the title fix(config): unresolved cjs import test: add test for cjs in optimizeDeps.include Aug 8, 2026
@yamachi4416
yamachi4416 marked this pull request as ready for review August 8, 2026 10:35
@yamachi4416
yamachi4416 requested a review from danielroe as a code owner August 8, 2026 10:35

@danielroe danielroe left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

do we really need a test fixture for this?

@coderabbitai

coderabbitai Bot commented Aug 8, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Added the examples/use-cjs Nuxt example. It defines pure and wrapped CommonJS packages, consumes them through default and namespace imports, and exposes composables and Vue components. It adds Nuxt, TypeScript, and Vitest configuration with Chromium testing. Vitest tests validate imports, composables, components, and application rendering. It also adds Vitest artifact ignore rules and fixes a workspace configuration import path.

Estimated code review effort: 3 (Moderate) | ~20 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ 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%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly identifies the missing file extension warning fix in the test examples.
Description check ✅ Passed The description relates to the missing extension fix, CommonJS test coverage, and Vitest result exclusions.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
examples/use-cjs/package.json (1)

18-18: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Pin @nuxt/test-utils to the tested release.

examples/use-cjs/vitest.config.ts uses defineVitestProject for both projects. This manifest pins Nuxt and Vitest but uses the moving latest tag for @nuxt/test-utils. The Nuxt changelog records browser setup support in @nuxt/test-utils 4.1.0, so pin the version tested with Nuxt 4.5.2 and Vitest 4.1.10. (nuxt.com)

🤖 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 `@examples/use-cjs/package.json` at line 18, Update the `@nuxt/test-utils`
dependency in the examples/use-cjs package manifest from the moving latest tag
to the tested 4.1.0 release, keeping the existing Nuxt and Vitest versions
unchanged.
🤖 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.

Inline comments:
In `@examples/use-cjs/libs/cjs-wrapper/index.d.ts`:
- Line 1: Update the declaration in index.d.ts to represent the default export
provided by index.mjs, while preserving the existing hello named export if
required. Model the default import’s actual runtime shape rather than reusing
the cjs-pure CommonJS object declaration.

In `@examples/use-cjs/nuxt.config.ts`:
- Around line 6-11: Update the optimizeDeps configuration in nuxt.config.ts to
restore noDiscovery: true alongside the existing include list, preserving
optimization of only the two listed packages.

---

Nitpick comments:
In `@examples/use-cjs/package.json`:
- Line 18: Update the `@nuxt/test-utils` dependency in the examples/use-cjs
package manifest from the moving latest tag to the tested 4.1.0 release, keeping
the existing Nuxt and Vitest versions unchanged.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 02065eb0-e22c-4f4d-af7c-d2d27359179a

📥 Commits

Reviewing files that changed from the base of the PR and between 5b8ffa4 and c028770.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (28)
  • .gitignore
  • examples/app-vitest-workspace/vitest.config.ts
  • examples/use-cjs/app/app.vue
  • examples/use-cjs/app/components/CjsPureDefault.vue
  • examples/use-cjs/app/components/CjsPureNamespace.vue
  • examples/use-cjs/app/components/CjsWrapperDefault.vue
  • examples/use-cjs/app/components/CjsWrapperNamespace.vue
  • examples/use-cjs/app/composables/useCjsPureDefault.ts
  • examples/use-cjs/app/composables/useCjsPureNamespace.ts
  • examples/use-cjs/app/composables/useCjsWrapperDefault.ts
  • examples/use-cjs/app/composables/useCjsWrapperNamespace.ts
  • examples/use-cjs/libs/cjs-pure/index.cjs
  • examples/use-cjs/libs/cjs-pure/index.d.ts
  • examples/use-cjs/libs/cjs-pure/package.json
  • examples/use-cjs/libs/cjs-wrapper/index.cjs
  • examples/use-cjs/libs/cjs-wrapper/index.d.ts
  • examples/use-cjs/libs/cjs-wrapper/index.mjs
  • examples/use-cjs/libs/cjs-wrapper/package.json
  • examples/use-cjs/nuxt.config.ts
  • examples/use-cjs/package.json
  • examples/use-cjs/test/nuxt/app-mount.spec.ts
  • examples/use-cjs/test/nuxt/cjs-components.spec.ts
  • examples/use-cjs/test/nuxt/cjs-composables-auto.spec.ts
  • examples/use-cjs/test/nuxt/cjs-composables-manual.spec.ts
  • examples/use-cjs/test/nuxt/cjs-import-default.spec.ts
  • examples/use-cjs/test/nuxt/cjs-import-namespace.spec.ts
  • examples/use-cjs/tsconfig.json
  • examples/use-cjs/vitest.config.ts

@@ -0,0 +1 @@
export declare function hello(): string

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== Candidate files =="
fd -a 'index\.(ts|js|mjs|d\.ts|tsconfig.*|package\.json|.*\.vue)$' examples/use-cjs | sort

echo
echo "== cjs-wrapper files =="
for f in \
  examples/use-cjs/libs/cjs-wrapper/index.d.ts \
  examples/use-cjs/libs/cjs-wrapper/index.mjs \
  examples/use-cjs/libs/cjs-wrapper/package.json \
  examples/use-cjs/libs/cjs-pure/index.d.ts \
  examples/use-cjs/libs/cjs-pure/index.mjs \
  examples/use-cjs/libs/cjs-pure/package.json \
  examples/use-cjs/app/components/CjsWrapperDefault.vue
do
  echo "--- $f"
  cat -n "$f"
done

echo
echo "== TS config / package metadata =="
for f in tsconfig*.json package.json example*/**/tsconfig*.json example*/**/package.json 2>/dev/null; do
  [ -f "$f" ] && echo "--- $f" && cat "$f"
done

echo
echo "== Search usage/import declarations =="
rg -n "from ['\"]@.*cjs|import \{|import .* \{" examples/use-cjs || true

Repository: nuxt/test-utils

Length of output: 1286


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== use-cjs tracked files =="
git ls-files examples/use-cjs | sort

echo
echo "== all occurrences mentioning cjs wrapper/pure/default import =="
rg -n "hello|CjsWrapperDefault|cjs-wrapper|cjs-pure|default|types|import:" examples/use-cjs || true

echo
echo "== package metadata in repository =="
cat -n package.json

echo
echo "== package scripts and type-check configuration =="
python3 - <<'PY'
import json, pathlib
p = pathlib.Path('package.json')
if p.exists():
    data=json.loads(p.read_text())
    print(json.dumps(data.get('scripts',{}), indent=2))
    print({k:v for k,v in data.items() if k in ('type','dependencies','devDependencies')})
PY

echo
echo "== cjs-wrapper source =="
for f in \
  examples/use-cjs/libs/cjs-wrapper/index.d.ts \
  examples/use-cjs/libs/cjs-wrapper/index.mjs \
  examples/use-cjs/libs/cjs-wrapper/index.cjs \
  examples/use-cjs/libs/cjs-wrapper/package.json \
  examples/use-cjs/libs/cjs-pure/index.d.ts
do
  [ -f "$f" ] && { echo "--- $f"; cat -n "$f"; }
done

Repository: nuxt/test-utils

Length of output: 16870


Fix the cjs-wrapper declaration for the default ESM import.

examples/use-cjs/libs/cjs-wrapper/index.mjs exports default, but index.d.ts only declares hello. TypeScript cannot type-check CjsWrapperDefault.vue with the current declaration, because the package’s runtime import contract is unrepresented.

Add a default export declaration or separate ESM/CommonJS declarations; cjs-pure/index.d.ts already models the CJS object shape and is not directly a valid ESM declaration here.

🤖 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 `@examples/use-cjs/libs/cjs-wrapper/index.d.ts` at line 1, Update the
declaration in index.d.ts to represent the default export provided by index.mjs,
while preserving the existing hello named export if required. Model the default
import’s actual runtime shape rather than reusing the cjs-pure CommonJS object
declaration.

Comment thread examples/use-cjs/nuxt.config.ts Outdated
Comment on lines +6 to +11
optimizeDeps: {
include: [
'example-use-cjs-cjs-pure',
'example-use-cjs-cjs-wrapper',
],
},

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf 'Repository files matching relevant names:\n'
rg -n "optimizeDeps|noDiscovery|example-use-cjs|examples/use-cjs" -S . || true

printf '\nRelevant config snippet:\n'
if [ -f examples/use-cjs/nuxt.config.ts ]; then
  nl -ba examples/use-cjs/nuxt.config.ts | sed -n '1,35p'
fi

printf '\nDiff/stat context:\n'
git diff --stat || true
git diff -- examples/use-cjs/nuxt.config.ts || true

printf '\nPackage manifests:\n'
if [ -f examples/use-cjs/package.json ]; then
  cat examples/use-cjs/package.json
fi

Repository: nuxt/test-utils

Length of output: 3123


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf 'examples/use-cjs/nuxt.config.ts lines 1-25:\n'
awk '{printf "%5d\t%s\n", NR, $0}' examples/use-cjs/nuxt.config.ts | sed -n '1,25p'

printf '\nexamples/use-cjs/package.json:\n'
cat examples/use-cjs/package.json

printf '\nsrc/config.ts optimizeDeps context:\n'
awk '{printf "%5d\t%s\n", NR, $0}' src/config.ts | sed -n '180,200p'

printf '\nDiff for examples/use-cjs/nuxt.config.ts:\n'
git diff -- examples/use-cjs/nuxt.config.ts || true

printf '\nSearch for noDiscovery in code/tests:\n'
rg -n "noDiscovery|optimizeDeps" -S src examples || true

Repository: nuxt/test-utils

Length of output: 2377


Restore optimizeDeps.noDiscovery in examples/use-cjs/nuxt.config.ts.

The example should exercise the no-discovery configuration while limiting optimization to the listed packages; keep include and add noDiscovery: true inside vite.optimizeDeps.

Proposed fix
   optimizeDeps: {
+    noDiscovery: true,
     include: [
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
optimizeDeps: {
include: [
'example-use-cjs-cjs-pure',
'example-use-cjs-cjs-wrapper',
],
},
optimizeDeps: {
noDiscovery: true,
include: [
'example-use-cjs-cjs-pure',
'example-use-cjs-cjs-wrapper',
],
},
🤖 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 `@examples/use-cjs/nuxt.config.ts` around lines 6 - 11, Update the optimizeDeps
configuration in nuxt.config.ts to restore noDiscovery: true alongside the
existing include list, preserving optimization of only the two listed packages.

@yamachi4416

Copy link
Copy Markdown
Member Author

@danielroe
Thank you for review.
for test-utils, we might not need a test case for this.
I’ll scope down the PR to just fixing the missing file extension warning and updating .gitignore.

@yamachi4416 yamachi4416 changed the title test: add test for cjs in optimizeDeps.include chore: avoid missing file extension warning in test/examples Aug 8, 2026
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