Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to disable Pre-transform error log? #7345

Open
hi-ogawa opened this issue Jan 23, 2025 · 4 comments · May be fixed by vitejs/vite#19272
Open

How to disable Pre-transform error log? #7345

hi-ogawa opened this issue Jan 23, 2025 · 4 comments · May be fixed by vitejs/vite#19272
Labels
p3-minor-bug An edge case that only affects very specific usage (priority)

Comments

@hi-ogawa
Copy link
Contributor

hi-ogawa commented Jan 23, 2025

Discussed in #7344

Originally posted by AlexKFU January 23, 2025
Hello! I have a monorepo project. In this monorepo i have a ui lib(jit package). Ui entrypoint looks like

export { default as TButton } from './TButton.vue'
export { useModal } from './useModalStore'

And i try mocking my library in test:

vi.mock('my-lib', () => (({
  useModal: () => {}
}))

i've got error in console

Pre-transform error: Failed to parse source for import analysis because the content contains invalid JS syntax. Install @vitejs/plugin-vue to handle .vue files. 

In vitest 2+ version i havent this error. For fix i can use vitejs/vue-plugin or direct import for my ui kit. But its strange and cant explain this behavior. Can i disable this log? Because the tests are actually passing.

Its my reproduce

you need to upgrade the vitest version in package json and you'll see error


Reproduction

https://stackblitz.com/edit/bolt-vue-wq7h39jr?file=vitest.config.ts

 DEV  v3.0.3 /home/projects/bolt-vue-vy5eu4e3

  src/composobles/bug/index.test.ts (1 test) 2ms
    bug reproduce > vi mock should work

 Test Files  1 passed (1)
      Tests  1 passed (1)
   Start at  17:58:44
   Duration  1.79s (transform 134ms, setup 0ms, collect 252ms, tests 2ms, environment 280ms, prepare 452ms)

 PASS  Waiting for file changes...
       press h to show help, press q to quit
5:58:45 PM [vite] (client) Pre-transform error: Failed to parse source for import analysis because the content contains invalid JS syntax. Install @vitejs/plugin-vue to handle .vue files.
  Plugin: vite:import-analysis
  File: /home/projects/bolt-vue-vy5eu4e3/src/uiLib/components/TButton/TButton.vue:2:25
  1  |  <template>
  2  |    <div>{{ hello }}</div>
     |                          ^
  3  |  </template>
  4  |  

System Info

  System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 18.20.3 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.2.3 - /usr/local/bin/npm
    pnpm: 8.15.6 - /usr/local/bin/pnpm
  npmPackages:
    vitest: 3.0.3 => 3.0.3 
@hi-ogawa
Copy link
Contributor Author

hi-ogawa commented Jan 23, 2025

This might be Vite 6's bug or Vitest 3's Vite 6 compat bug.

Vitest has been using server.preTransformRequests: false, but it looks like Vite 6 now needs environments.client.dev.preTransformRequests: false for jsdom/happy-dom environment.

preTransformRequests: false,

https://stackblitz.com/edit/bolt-vue-stgk6ecc?file=vitest.config.ts

  // TODO: Vite bug? probably this is supposed to work
  // server: {
  //   preTransformRequests: false,
  // },
  environments: {
    client: {
      dev: {
        preTransformRequests: false,
      },
    },
  },

@hi-ogawa hi-ogawa added the p3-minor-bug An edge case that only affects very specific usage (priority) label Jan 23, 2025
@hi-ogawa hi-ogawa linked a pull request Jan 23, 2025 that will close this issue
@AlexKFU
Copy link

AlexKFU commented Jan 23, 2025

this is a good solution, but what if in some tests i need to use jsdom?

@hi-ogawa
Copy link
Contributor Author

@AlexKFU It should be fine to keep jsdom. It's just that Vite 6 changed how preTransformRequests is handled and we need to fix somewhere on Vite or Vitest to keep the same behavior as before.

@AlexKFU
Copy link

AlexKFU commented Jan 24, 2025

thx a lot!:)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants