Skip to content

fix: auto-import does not work when using @vitejs/plugin-vue alone - #1412

Merged
aklinker1 merged 1 commit into
wxt-dev:mainfrom
aiktb:main
Feb 12, 2025
Merged

aklinker1 merged 1 commit into
wxt-dev:mainfrom
aiktb:main

Conversation

@aiktb

@aiktb aiktb commented Feb 8, 2025

Copy link
Copy Markdown
Contributor

close #1356

wxt uses its own unimport vite plugin instead of the official vite plugin, which causes the auto-import in the vue file to fail (instead of using @wxt-dev/module-vue, it uses @vitejs/plugin-vue directly)

The problem was fixed after applying this patch at https://github.com/aiktb/vue-browser-test.git, so I can be sure that this is the problem.

This should also close unjs/unimport#419 as this is not a unimport bug. cc @aklinker1

By comparing the source code of WXT and unimport, I found the problem. The vite plugin implemented by WXT lacks the following key code:
https://github.com/unjs/unimport/blob/6265894d07500d3ce0e24b247bdbb12e37a559d8/src/unplugin.ts#L48

enforce: 'post',

https://vite.dev/guide/using-plugins#enforcing-plugin-ordering
It is indeed caused by the execution order of the vite plugin.

@netlify

netlify Bot commented Feb 8, 2025

Copy link
Copy Markdown

Deploy Preview for creative-fairy-df92c4 ready!

Name Link
🔨 Latest commit f1f65d2
🔍 Latest deploy log https://app.netlify.com/sites/creative-fairy-df92c4/deploys/67a755061868b70008c2cb0f
😎 Deploy Preview https://deploy-preview-1412--creative-fairy-df92c4.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@aiktb
aiktb marked this pull request as draft February 8, 2025 13:07
@aiktb
aiktb marked this pull request as ready for review February 8, 2025 14:02

@Timeraa Timeraa 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.

Code looks fine can't test myself right now though.

@pkg-pr-new

pkg-pr-new Bot commented Feb 8, 2025

Copy link
Copy Markdown

Open in Stackblitz

@wxt-dev/auto-icons

npm i https://pkg.pr.new/@wxt-dev/auto-icons@1412

@wxt-dev/i18n

npm i https://pkg.pr.new/@wxt-dev/i18n@1412

@wxt-dev/module-solid

npm i https://pkg.pr.new/@wxt-dev/module-solid@1412

@wxt-dev/module-react

npm i https://pkg.pr.new/@wxt-dev/module-react@1412

@wxt-dev/module-svelte

npm i https://pkg.pr.new/@wxt-dev/module-svelte@1412

@wxt-dev/module-vue

npm i https://pkg.pr.new/@wxt-dev/module-vue@1412

@wxt-dev/storage

npm i https://pkg.pr.new/@wxt-dev/storage@1412

@wxt-dev/unocss

npm i https://pkg.pr.new/@wxt-dev/unocss@1412

wxt

npm i https://pkg.pr.new/wxt@1412

commit: f1f65d2

@codecov

codecov Bot commented Feb 8, 2025

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 50.00000% with 1 line in your changes missing coverage. Please review.

Project coverage is 81.11%. Comparing base (0d56100) to head (f1f65d2).
Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
packages/wxt/src/testing/wxt-vitest-plugin.ts 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1412      +/-   ##
==========================================
- Coverage   81.22%   81.11%   -0.11%     
==========================================
  Files         128      128              
  Lines        6296     6271      -25     
  Branches     1073     1066       -7     
==========================================
- Hits         5114     5087      -27     
- Misses       1167     1169       +2     
  Partials       15       15              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@aklinker1

Copy link
Copy Markdown
Member

Hmm, interesting. I swear I added enforce: 'post', but maybe that was somewhere else... Thanks for the PR. Will test soon as well. Traveling today

@aklinker1 aklinker1 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.

Yeah, seems to work. Will merge and release!

@aklinker1
aklinker1 merged commit d6ee456 into wxt-dev:main Feb 12, 2025
@aklinker1

Copy link
Copy Markdown
Member

Released in v0.19.27

zizzfizzix pushed a commit to zizzfizzix/wxt that referenced this pull request Aug 29, 2026
`unimport/unplugin` calls `MagicString#generateMap()` with no options,
which produces a line-level sourcemap with no `source`. Since auto-imports
are injected at the top of the file, tools that rely on columns - like V8
code coverage - see the whole module as a single statement.

The result is that any module referencing an auto-imported variable
(`browser`, `storage`, ...) silently drops out of coverage reports, which
inflates the reported percentage and lets thresholds pass when they
shouldn't.

This was fixed once in wxt-dev#381, but wxt-dev#1412 replaced the `wxt:unimport` plugin
with `UnimportPlugin.vite()` in both the build path and `WxtVitest()`,
dropping the `hires` option along the way.

Restore the `wxt:unimport` plugin with the sourcemap options from wxt-dev#381,
keeping the `enforce: 'post'` ordering and the include/exclude filter that
wxt-dev#1412 relied on. The defaults are imported from `unimport/unplugin`, so
they can't drift. Both the build path and `WxtVitest()` share the plugin.

Fixes wxt-dev#2604

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011PEx8LKp7AtQkR3tJfyFrY
zizzfizzix pushed a commit to zizzfizzix/wxt that referenced this pull request Aug 29, 2026
`unimport/unplugin` calls `MagicString#generateMap()` with no options,
which produces a line-level sourcemap with no `source`. Since auto-imports
are injected at the top of the file, tools that rely on columns - like V8
code coverage - see the whole module as a single statement.

The result is that any module referencing an auto-imported variable
(`browser`, `storage`, ...) silently drops out of coverage reports, which
inflates the reported percentage and lets thresholds pass when they
shouldn't.

This was fixed once in wxt-dev#381, but wxt-dev#1412 replaced the `wxt:unimport` plugin
with `UnimportPlugin.vite()` in both the build path and `WxtVitest()`,
dropping the `hires` option along the way.

Restore the `wxt:unimport` plugin with the sourcemap options from wxt-dev#381,
keeping the `enforce: 'post'` ordering and the include/exclude filter that
wxt-dev#1412 relied on. The defaults are imported from `unimport/unplugin`, so
they can't drift. Both the build path and `WxtVitest()` share the plugin.

Fixes wxt-dev#2604

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011PEx8LKp7AtQkR3tJfyFrY
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.

Imports added outside Vue <script> block

3 participants