useAsyncData in combination with --coverage (istanbul) causes syntax error
Error: SyntaxError: Expecting Unicode escape sequence \uXXXX (1:1)
Happens when using the @vitest/coverage-istanbul coverage provider. V8 Does work (but i have never been able to create accurate coverage reports with that)
Even when using useLazyAsyncData or // useAsyncData
reproduction: https://stackblitz.com/edit/nuxt-starter-1ens2b
run pnpm run test
I hope I did this correctly, but for me it seems with latest version & latest nuxt you can reproduce this anywhere if you just add // useAsyncData I guess that is because of the auto imports.
Stacktrace example:
FAIL app.test.ts [ app.test.ts ]
SyntaxError: Expecting Unicode escape sequence \uXXXX (1:1)
❯ pp$4.raise node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/chunks/dep-df561101.js:25027:13
❯ pp.invalidStringToken node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/chunks/dep-df561101.js:27176:10
❯ pp.readWord1 node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/chunks/dep-df561101.js:27340:16
❯ pp.readWord node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/chunks/dep-df561101.js:27359:19
❯ pp.readToken node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/chunks/dep-df561101.js:26647:19
❯ pp.nextToken node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/chunks/dep-df561101.js:26640:15
❯ Parser.parse node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/chunks/dep-df561101.js:22063:8
❯ Function.parse node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/chunks/dep-df561101.js:22114:35
❯ TransformContext.parse node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/chunks/dep-df561101.js:43962:27
❯ TransformContext.transform node_modules/.pnpm/@[email protected][email protected]/node_modules/@nuxt/vite-builder/dist/shared/vite-builder.d6a45f81.mjs:947:24
My workaround for now to get past the CI checks is to make a wrapper composable
import { AsyncDataOptions } from "nuxt/app";
export const useWrapperAsyncData = <T = any>(
...args: [string, () => Promise<T>, AsyncDataOptions<T>]
) => useAsyncData(...args);
Somehow this fixes my issue :/
Hope to find a real fix soon though!
This issue appears for me as well on Node.js 18.19.1 only on GitLab CI, the runner platform is amd64/linux.
Do we have any updates, workarounds, or fixes planned?
I'm facing the same error.
I could make it fail with a small project. I'll push it tomorrow just in case someone wants an easy way to reproduce it 👍
@rubennaatje, I did not use any useAsyncData on my test project, do you have any other tips?
Sorry for the long delay.
I hope we can give this issue more attention. Using @rubennaatje's solution seems to be the way to go for now, but it feels a bit weird to use it as a final solution.
Here is the project In case someone wants to see the error happening.
In my opinion, this issue causes significant confusion, making it difficult to test the code and reducing confidence in the libraries/frameworks. If a company relies on testing as part of its workflow, it could face major setbacks because of this issue.
Hey! @manniL first of all love your videos! Have you ever faced something like this before?