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

magic-string error #4907

Closed
6 tasks done
ferparra opened this issue Jan 8, 2024 · 6 comments · Fixed by #4916
Closed
6 tasks done

magic-string error #4907

ferparra opened this issue Jan 8, 2024 · 6 comments · Fixed by #4916
Labels
documentation Improvements or additions to documentation

Comments

@ferparra
Copy link

ferparra commented Jan 8, 2024

Describe the bug

Getting the following error after pnpm exec vitest

Error: Cannot use replaced character 610 as slice start anchor.
 ❯ MagicString.slice node_modules/.pnpm/[email protected]/node_modules/magic-string/dist/magic-string.es.mjs:924:10
 ❯ Object.transform node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/chunks/dep-V3BH7oO1.js:64060:62
 ❯ loadAndTransform node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/chunks/dep-V3BH7oO1.js:49741:29

Reproduction

Try using vi.hoisted in your code. I am not able to identify how to reproduce exactly because I'm unsure how to debug properly.

System Info

System:
    OS: macOS 14.2.1
    CPU: (8) arm64 Apple M2
    Memory: 59.13 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 21.5.0 - /opt/homebrew/bin/node
    npm: 10.2.4 - /opt/homebrew/bin/npm
    pnpm: 8.14.0 - /opt/homebrew/bin/pnpm
  Browsers:
    Safari: 17.2.1
  npmPackages:
    @vitejs/plugin-react: ^4.2.1 => 4.2.1 
    vitest: ^1.1.3 => 1.1.3

Used Package Manager

pnpm

Validations

Copy link

github-actions bot commented Jan 8, 2024

Hello @ferparra. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with need reproduction will be closed if they have no activity within 3 days.

@sheremet-va
Copy link
Member

Reproduction stackblitz.com/edit/vitest-dev-vitest-uqbyyy?file=test%2Fbasic.test.ts&initialPath=vitest

This should give an error, but a different one. Is there a reason why you are calling vi.mock inside vi.hoisted? It's already hoisted. vi.hoisted is meant to be used to define variables that should be used inside vi.mock

@sheremet-va sheremet-va added bug documentation Improvements or additions to documentation and removed needs reproduction labels Jan 9, 2024
@ferparra
Copy link
Author

ferparra commented Jan 9, 2024

You are correct @sheremet-va. It was unnecessary.

Now the error is gone :)

@ferparra ferparra closed this as completed Jan 9, 2024
@getriebesand
Copy link

my case I wanted to debug a problem with nuxt test-utils. This was probably not the right way, but I came across this error message, which I couldn't do anything with.

@sheremet-va
Copy link
Member

We should define a better error message, so I will keep the issue open for now, if it's ok with you.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Improvements or additions to documentation
Projects
None yet
3 participants