Closed rmunn closed 3 years ago
See #14
If I move svelte-kit-cookie-session into devDependencies
then the error message changes:
1:22:41 PM [vite] Error when evaluating SSR module (REPOROOT)/src/hooks:
Error: Cannot find module 'svelte-kit-cookie-session' from '(REPOROOT)/src'
And then pnpm run build
works but pnpm run preview
does not:
> (PROJECTNAME)@0.0.1 preview (REPOROOT)
> svelte-kit preview
> Cannot find package '(REPOROOT)/node_modules/svelte-kit-cookie-session/' imported from (REPOROOT)/.svelte-kit/output/server/app.js
This is all with the latest Svelte-Kit and Vite, BTW.
I haven't quite figured out which vite config is helpful here. Would be happy to include something in the README.
Saw your reference to https://github.com/vitejs/vite/issues/728 which does look like exactly the issue... but that issue is closed and locked, so I bet the Vite developers aren't tracking it. I wonder if I should open a new issue in Vite to report this? I bet we could boil this down to a VERY simple reproduction with no Svelte-Kit in the mix, so that the Vite devs don't end up thinking the problem is in Svelte-Kit.
Hmm. I'll hold off on opening a Vite issue until I have a Vite-only repro, I think. But it's definitely something VIte-side that's causing this.
This seems definetly like a Vite issue, i'm trying around with the vite config to see if i can solve this issue that way.
@rmunn @chbert I found 2 different solution, this is the easiest one which should work..
const config = {
kit: {
vite: {
optimizeDeps: {
exclude: ['svelte-kit-cookie-session'],
},
},
},
};
@pixelmund That doesn't work for me. I also tried optimizeDeps: { esbuildOptions: { platform: 'neutral' } }
without checking dev and I'm still getting "error: Could not read from file: (REPOROOT)/crypto". The app does run and correctly decrypts and encrypts session cookies, but esbuildOptions: { platform: 'neutral' }
isn't working.
I also tried this:
optimizeDeps: {
allowNodeBuiltins: ['crypto'],
esbuildOptions: { platform: 'neutral' }
}
But that didn't change anything; I'm still getting the same "Could not read from file" error.
So did you try the exclude
one?
I can't reproduce it anymore, even after deleting node_modules
the exclude
did the trick..
Just tried exclude
and it worked -- before seeing your comment edit above. :-)
optimizeDeps: {
exclude: ['svelte-kit-cookie-session'],
}
That was enough to get rid of the Vite error.
Perfect, i'm adding it to the readme. Thanks for verifying :-)
Note that svelte-kit-cookie-session does need to be in dependencies
, not devDependencies
, or I still get "Error: Cannot find module 'svelte-kit-cookie-session' from '(REPOROOT)/src'".
Perfect, i'm adding it to the readme. Thanks for verifying :-)
Great; I'll close the issue once the README is updated, or you can close it if I don't get to it. (I'm in a far eastern timezone, UTC+lots, so I go to sleep while most of America is just waking up).
I have updated the README and going to close this issue now. I'm on UTC+1
Just updated svelte-kit-cookie-session from 1.2.4 to 1.3.0, and now I'm getting the following Vite error whenever I run
pnpm run dev
:(I replaced my repo root with the text
(REPOROOT)
above since I'm running this from a directory nested about five deep in my folder hierarchy, and without that replacement the error message was even more annoyingly long than it already is.)Running with
npm
instead ofpnpm
I get the same error. However, if I runpnpm run build
followed bypnpm run preview
then everything works.I know I need to somehow tell Vite that
svelte-kit-cookie-session
is only Node-based and should therefore be allowed to import Node packages likecrypto
, but I'm not yet familiar enough with Svelte-Kit to know how to do that off the top of my head. Which leads me to report it here, because you might want to add something to the svelte-kit-cookie-session README about how to work around this Vite behavior. (And I'll update this issue if I figure it out.)