question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error: [vite-plugin-ssr@0.4.43][Wrong Usage][`navigate(url)`] Something is wrong with your environment (it loads the wrong `vite-plugin-ssr/client/router` entry). This may be happening if you use Jest or Babel. Open a new GitHub issue to discuss a solution.

See original GitHub issue

Question / Discussion

After adding import { navigate } from 'vite-plugin-ssr/client/router' to one of my components I now get the following error when trying to test it:

Error: [vite-plugin-ssr@0.4.43][Wrong Usage][`navigate(url)`] Something is wrong with your environment (it loads the wrong `vite-plugin-ssr/client/router` entry). This may be happening if you use Jest or Babel. Open a new GitHub issue to discuss a solution.

I am using React Testing Library to render and test my component. I am not using Jest or Babel.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
brilloutcommented, Nov 1, 2022

Let me know if you need the fix to be released sooner rather than later.

Also, in case your employer has the financial capabilities: https://github.com/sponsors/brillout. Sponsors make a huge difference and allow me to further work on VPS.

0reactions
robinelvincommented, Nov 1, 2022

From my investigations it looks like it’s: https://github.com/brillout/vite-plugin-ssr/blob/8f8cab47c2a229ab6161e8bb01d3fda447602ceb/vite-plugin-ssr/node/client/router.ts#L6

In tests this is being evaluated when the function is imported and as the tests run in a jsdom environment under Node it fails the assertion. If I remove this assertion my tests then run as expected. However, in a component which uses navigate I now get:

Error: [vite-plugin-ssr@0.4.43][Wrong Usage][`navigate(url)`] The `navigate(url)` function is only callable in the browser but you are calling it in Node.js.

I’m not sure what the solution is. I think I need some guidance on how testing should be done.

Fixed my test by adding:

vi.mock('vite-plugin-ssr/client/router', () => {
    return {
        navigate: vi.fn(),
    };
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

[Bug]: Module Import Stack Trace sometimes broken · Issue ...
Version 29.0.3 Steps to reproduce Clone this repo: git clone https://github.com/smcenlly/jest-stack-trace-issue Install dependencies npm install From the ...
Read more >
Vite compatible Jest preset · Issue #1149 · vitejs/vite - GitHub
I 'm migrating a large codebase to Vue 3 + Vite. The project contains tests I'd like to reuse. But due to the...
Read more >
Tests Fail Using Basic Configuration (React Native/TypeScript ...
Ultimately - I just wanted to move to SWC to get faster, more stable, and ultimately the most performant tests I can run)....
Read more >
jest: Test suite failed to run, TypeError: Cannot read property ...
we were using jest from unit testing in react-native. It was working well. We just deleted npm and installed it again and then...
Read more >
Requires Babel "^7.0.0-0", but was loaded with "6.26.3". #6913
Bug Report I get the following message when trying to run tests. None of the solutions in the documentation or other issues work....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found