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

import { navigate } internal assertion failed #91

Closed
chrisvariety opened this issue Jun 9, 2021 · 13 comments
Closed

import { navigate } internal assertion failed #91

chrisvariety opened this issue Jun 9, 2021 · 13 comments

Comments

@chrisvariety
Copy link
Contributor

chrisvariety commented Jun 9, 2021

(congrats on the 0.1.0 release!)

Happy to put together a sandbox/repro, just let me know.

Code like this is failing for me, not within vite itself, but within my test suite (jest):

import { navigate } from 'vite-plugin-ssr/client/router';

    [vite-plugin-ssr@0.1.0][Internal Failure] You stumbled upon a bug in `vite-plugin-ssr`'s source code (an internal assertion failed). This should definitely not be happening, and you should create a new issue at https://github.com/brillout/vite-plugin-ssr/issues/new that includes this error stack (the error stack is enough to debug this). Or reach out on Discord. A fix will be written promptly.

      at Object.<anonymous> (node_modules/vite-plugin-ssr/client/router/index.node.ts:5:1)
      at Object.<anonymous> (node_modules/vite-plugin-ssr/client/router/index.js:2:18)
      at Object.<anonymous> (pages/session.page.tsx:29:1)
      at Object.<anonymous> (pages/__tests__/session.page.spec.tsx:2:1)

It seems like vite-plugin-ssr/client/router could either resolve to index.js or index.ts, and certain environments will prefer the index.js, which trips this internal assertion.

@brillout
Copy link
Member

brillout commented Jun 9, 2021

Is this happening on a speical CI env or locally on your machine?

Something's weird with your CI env, see node_modules/vite-plugin-ssr/client/router/index.js:2:

module.exports = require('../../dist/cjs/client/router/index.node.js')

So it should load node_modules/vite-plugin-ssr/dist/cjs/client/router/index.node.js but surprisingly your env is loading node_modules/vite-plugin-ssr/client/router/index.node.ts instead.

Does your env change the require behavior? Node.js version?

congrats on the 0.1.0 release!

Thanks :-)

@chrisvariety
Copy link
Contributor Author

chrisvariety commented Jun 9, 2021

node v14.16.1

Here's what I think is a trivial reproduction, tho the stack trace is weird on code sandbox: https://codesandbox.io/s/red-bash-2mob5?file=/src/index.ts

As far as I can tell this will occur when using babel to transpile/execute import { navigate } from 'vite-plugin-ssr/client/router';. I know it's a bit weird to use babel with this library (since vite is powered by esbuild), but a lot of testing libraries (particularly jest) use babel internally to execute tests, and vite doesn't have a first class jest integration quite yet.

@brillout
Copy link
Member

brillout commented Jun 9, 2021

So your goal is to unit test a component? Do you want to then also test the naviagte() function?

I'll have a look at why Babel transpiles erroneously.

@chrisvariety
Copy link
Contributor Author

You got it! Not planning to test navigate() at this time, it's just included on the component.

@brillout
Copy link
Member

brillout commented Jun 9, 2021

Then simply removing the assert(isNodejs()) will likely solve the problem.

Let me first have a look at how Babel transpiles, to see if it's a bug on vite-plugin-ssr's part or on Babel's part.

Note that for testing navitage() you'll need to use Vite instead of Babel.

@chrisvariety
Copy link
Contributor Author

Sounds good. Yeah, that would be more of an end to end test, I'm more trying to check the component renders properly with various props.

@brillout
Copy link
Member

brillout commented Jun 9, 2021

Let me know if you still encouter problems.

Btw. I'm curious: how has Vite been working out for you so far?

@chrisvariety
Copy link
Contributor Author

@brillout thanks much, latest version works great to me.

Vite's been working out well, it's just other tools that need to catch up!

@brillout
Copy link
Member

it's just other tools that need to catch up

If you don't mind me asking: what tools have been difficult to use with Vite? Other than Jest.

@chrisvariety
Copy link
Contributor Author

Storybook comes to mind: https://storybook.js.org

Everything is very "experimental" "early stages" etc. https://github.com/eirslett/storybook-builder-vite

Deno comes to mind as well... vitejs/vite#109

@brillout
Copy link
Member

I see, thanks.

@brillout
Copy link
Member

The lead seems quite pushy about supporting Vite storybookjs/storybook#14024. Probably only a question of time.

As for Deno, it's more a Deno problem if you ask me. Deno is just too much of a drastic change for the ecosystem willing to migrate. The only real benefit of Deno is the ability the run scripts with lesser permissions, which so far hasn't been a USP enough to justify migration cost. Hopefully things will change, I like Deno.

Let me know if you have further integration problems.

@brillout
Copy link
Member

(I care a lot about smooth integrations.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants