Sample app errors
SGarno opened this issue · comments
I am getting the following errors on the sample app:
8:47:01 AM [vite] Error when evaluating SSR module /@fs/D:/Development/svelte/sk-auth/dist/index.js:
ReferenceError: exports is not defined
at /@fs/D:/Development/svelte/sk-auth/dist/index.js:3:23
at instantiateModule (D:\Development\svelte\sk-auth\app\node_modules\vite\dist\node\chunks\dep-e9a16784.js:68197:166)
8:47:01 AM [vite] Error when evaluating SSR module /@fs/D:/Development/svelte/sk-auth/dist/providers/index.js:
ReferenceError: exports is not defined
at /@fs/D:/Development/svelte/sk-auth/dist/providers/index.js:3:23
at instantiateModule (D:\Development\svelte\sk-auth\app\node_modules\vite\dist\node\chunks\dep-e9a16784.js:68197:166)
This is from a fresh clone of sk-auth and then npm run dev
in the app directory.
Hmm. It's possible I broke something, I'll give it a look!
This is interesting. The error you're getting is different from mine; which is:
17:37:42 [vite] Error when evaluating SSR module /src/lib/appAuth.ts:
SyntaxError: Unexpected token '.'
at new Function (<anonymous>)
at instantiateModule (C:<anonymous>sk-auth\app\node_modules\vite\dist\node\chunks\dep-e9a16784.js:68197:9)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
Vite really seems to have trouble with its job. 😅
i have the same error. it comes from CJS build. svelte kit use ESM build. if u change it all start works as expected
So switch to ESM and reinstall the package fresh? How come it worked only a couple of hours ago? I'll give it a try and report back!
So, unless I did something wrong it still doesn't work. I switched the build to ESM by making the following change to rollup.config.js
:
export default [
{
...config,
output: {
dir: "dist",
sourcemap: true,
format: "esm",
},
]
I made sure to properly reinstall the packages as well, removed any residue dist/
folders, etc. to no avail.
i used the sample app with ESM build and run yarn/npm install in sample app and sk-auth. and conflict with "ReferenceError: exports is not defined" disappears
That worked for me.
Thanks for the response guys, do you mind making a PR or sharing the config so we can get this sorted out in the main repo? I haven't been able to make the right adjustments it seems. Would appreciate the help!
EDIT: The adjustments I tried are in the enhancements/esm branch in case anyone is interested in giving that a look.
Just do a yarn add --dev build-esm
to your project and the app. Then just build.
Wow, that's insane! Did SvelteKit get a recent update that broke this? I initially attempted recompiling the lib itself to ESM instead of CommonJS which had the same errors as before.
Not sure relative to what version you have of SK. I am using SvelteKit v1.0.0-next.109
Looks like we'll need to make esm-build
a peer dependency of SKA then.
Alright, so I'm trying those changes again but unless I'm doing something wrong, it still doesn't work for me. The output is a new one, though:
Error: Cannot find module 'sk-auth' from 'C:/<anonymous>/SvelteKitAuth/app/src/lib'
at Function.resolveSync [as sync] (C:\<anonymous>\SvelteKitAuth\app\node_modules\resolve\lib\sync.js:102:15)
at resolveFrom$6 (C:\<anonymous>\SvelteKitAuth\app\node_modules\vite\dist\node\chunks\dep-e9a16784.js:4052:29)
at resolve (C:\<anonymous>\SvelteKitAuth\app\node_modules\vite\dist\node\chunks\dep-e9a16784.js:68232:22)
at nodeRequire (C:\<anonymous>\SvelteKitAuth\app\node_modules\vite\dist\node\chunks\dep-e9a16784.js:68211:25)
at ssrImport (C:\<anonymous>\SvelteKitAuth\app\node_modules\vite\dist\node\chunks\dep-e9a16784.js:68164:20)
at eval (/src/lib/appAuth.ts:3:674)
at instantiateModule (C:\<anonymous>\SvelteKitAuth\app\node_modules\vite\dist\node\chunks\dep-e9a16784.js:68197:166)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
From the error message, looks like you are linking to sk-auth via file system rather than an install from npm and it appears to behave like it can't resolve the link: (or file:) alias. Can you check your package.json and confirm it is pointing to the right directory?
When I was using sk-auth from a directory, my package.json had the following:
"dependencies": {
"sk-auth": "file:../sk-auth"
}
I started over with a vanilla SK project and it seemed to be including it ok, however, I ran into a different issue (#25).
Could it be related to your npm / yarn version?
That somewhat makes sense, although file:
should definitely copy over all the files instead of creating a symlink. I have to give #25 a look but there still seems to be a lot of trouble with the installation which are issues that need to be sorted out before we can move forward.
Alright! I got it working. It was an issue with some residue configurations from previous attempts to solve the issue, I'll have a PR ready to merge soon and then give the other issues a look.