-
Notifications
You must be signed in to change notification settings - Fork 71
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
Unit test error using 'Vitest, @nuxt/test-utils' (SyntaxError: At least one <template> or <script> is required for each file component. ) #842
Comments
The error message you're encountering, "SyntaxError: At least one or <script> is required in a single file component," suggests a misinterpretation of the file content by the testing framework or the Vue file parser. This is likely due to the unconventional use of Ensure your testing setup, including configurations for Vitest and @nuxt/test-utils, properly supports Vue single file components (SFCs) and TypeScript. This involves correctly setting up the Nuxt configuration file ( Review your configuration files for any discrepancies or misconfigurations. If the problem persists, it could be due to compatibility issues between Vitest, @nuxt/test-utils, and Vue 3.4.21. Compatibility concerns have been noted in the changelogs for these tools, which could be contributing to the error you're seeing. This approach should help you resolve the error and ensure your testing environment is correctly configured for your Nuxt and Vue application.
|
Currently facing this issue at the moment, if you remove |
I am facing the same problem. I am relieved to see someone else facing the same problem. |
You should not add the Vue plugin to your vitest config - |
@danielroe |
Environment
package.json
Reproduction
npm install
in the environment imported to localnpx vitest index
Github:https://github.com/motoo1789/nuxt-test-utils_report
Describe the bug
Objective:
I want to test an API via useFetch from Vuetify components.
Error occurrence:
To achieve this goal, I've used '@nuxt/test-utils/runtime'.
However, I encountered errors in the logs.
To identify the cause, I've minimized the provided repository.
As a result, it seems that an error occurs when "index.vue" is imported and used.
Previously, I was using 'import { defineConfig } from "vite";' in vitest.config.ts and there were no errors in the logs at that time.
Both
<templage> <script>
are present in index.vue.Could you please advise me on this.
Additional context
As a solution for related errors, you can remove Vue() from the plugin in the vite.config.m{ts|js} file.
If you remove Vue() from plugins in the vitest.config.m{ts|js} file it complains Vuetify needs to be loaded before the Vue plugin.
No response
Logs
The text was updated successfully, but these errors were encountered: