#Should API route deps be downloaded and run in browser?

12 messages · Page 1 of 1 (latest)

obtuse light
#

Some packages don't run in browser (e.g. Prisma, jsonwebtoken), so the site breaks when hitting an API endpoint with resource

Am I doing something wrong? Or is this expected?

I can provide a code example if needed, but figured the concept is pretty general so I didn't include one.

terse forge
obtuse light
#

Thanks @terse forge

steep ibex
#

hmm normally the server deps are not used by the client callback functions and then they won't be imported. So if that's happening, check out the JS that was generated (the file in the browsers that shows the error, you'll have to turn off sourcemaps maybe) and try to figure out why the client callback has the server module in its dependency graph

obtuse light
#

I think this is the same issue linked above, it happens when using the Link component to navigate pages

steep ibex
#

Best way to know exactly what's going on is looking at the built .js files and seeing which ones try to import the wrong package

obtuse light
#

Yes, when using the Link component, all of the API routes and their dependencies are getting downloaded when a link is clicked.

steep ibex
#

so you need to find the first dep that does this. Perhaps it's indeed Link and the optimizer is confused about its server and client use, but you have to check

obtuse light
#

Ok, changing the Link to an a tag resolves the issue, can you give me a little more info on how to track down that generated file? (please pardon my mental slowness, I have covid, just starting to be functional again today)

#

I can give you access to the repo if that makes things easier?

steep ibex
#

Can you reproduce it in https://qwik.new ? Then it will be easier to sift through.
In any case, in the browser you should be able to see where the error arises. It will be coming from some js file that tries to import some server module. Figure out which code that is.

terse forge
#

@steep ibex the linked issue contains a stackblitz looks like