Closed andykais closed 3 years ago
on a related note, building the project (as opposed to running the dev server) results in this error:
andrew sveltekit-supabase-bug npm run build
> sveltekit-supabase-bug@0.0.1 build /home/andrew/Code/development/sveltekit-supabase-bug
> svelte-kit build
Transforming...
✔ client
✔ server
Optimizing...
⧗ client
⧗ server
> 'process' is imported but could not be bundled
Error: 'process' is imported but could not be bundled
at error (/home/andrew/Code/development/sveltekit-supabase-bug/node_modules/rollup/dist/shared/rollup.js:5265:30)
at throwPluginError (/home/andrew/Code/development/sveltekit-supabase-bug/node_modules/rollup/dist/shared/rollup.js:17949:12)
at Object.error (/home/andrew/Code/development/sveltekit-supabase-bug/node_modules/rollup/dist/shared/rollup.js:18556:24)
at find_deps (/home/andrew/Code/development/sveltekit-supabase-bug/node_modules/@sveltejs/kit/src/api/build/index.js:164:13)
at /home/andrew/Code/development/sveltekit-supabase-bug/node_modules/@sveltejs/kit/src/api/build/index.js:159:11
at Array.forEach (<anonymous>)
at find_deps (/home/andrew/Code/development/sveltekit-supabase-bug/node_modules/@sveltejs/kit/src/api/build/index.js:154:17)
at get_deps (/home/andrew/Code/development/sveltekit-supabase-bug/node_modules/@sveltejs/kit/src/api/build/index.js:174:7)
at /home/andrew/Code/development/sveltekit-supabase-bug/node_modules/@sveltejs/kit/src/api/build/index.js:188:37
at Array.forEach (<anonymous>)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! sveltekit-supabase-bug@0.0.1 build: `svelte-kit build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the sveltekit-supabase-bug@0.0.1 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/andrew/.npm/_logs/2020-12-04T19_14_36_594Z-debug.log
which seems to clearly be stating that it is attempting to bundle the built in nodejs module process
for the browser.
Updated:
The issue context is @supabase/gotrue-js using process
to detect constants
The issue from @sveltejs/kit
itself
They treat process
as external package and prevent snowpack:rollup-plugin-node-process-polyfill
handle it for the browser.
From @sveltejs/snowpack-config/snowpack.config.js
:
/* ... */
installOptions: {
// ignore `import fs from 'fs'` etc
externalPackage: require('module').builtinModules // NOTE: this include `process` package
},
/* ... */
My workaround for @sveltejs/kit users:
// From your project snowpack.config.js, add this:
// ...
installOptions: {
externalPackage: require('module').builtinModules.filter(pkg_name => pkg_name !== "process")
},
// ...
My English is not good
Hey @langbamit I just released a new version. Can you please reinstall supabase npm install @supabase/supabase-js@latest
and try again?
@kiwicopple, @langbamit thanks for your help. I just updated the deps to latest and added the suggested fix to my snowpack.config.js, I still see the same error.
andrew sveltekit-supabase-bug npm ls --depth=0
sveltekit-supabase-bug@0.0.1 /home/andrew/Code/development/sveltekit-supabase-bug
├── @supabase/supabase-js@1.1.4
├── @sveltejs/adapter-node@1.0.0-next.0
├── @sveltejs/kit@1.0.0-next.17
├── @sveltejs/snowpack-config@1.0.0-next.0
└── svelte@3.31.2
I have updated the repro repo here https://github.com/andykais/supabase-svelte-kit-bug-repro
SyntaxError: [778:36]: Unexpected token: 'get'
This issue related to https://github.com/meriyah/meriyah/issues/164 issue, which is fixed in v4.0.0.
We can't testing it by add resolutions: { "meriyah": "4.0.0" }
to prepro repo, because @sveltejs/kit
bundled this package inside their code (svelte-kit still in alpha state)
I think we can close this issue now.
This issue should be closed and new issue made if it still persists with the open beta version of sveltekit. Should be noted that Sveltekit dropped Snowpack and use Vite instead (https://github.com/vitejs/vite)
hi, yes there is still an issue with the public beta version of sveltekit (or more probably, vite)
this is the error that happens when i require supabase in an api route:
500
ENOENT: no such file or directory, open '/Users/swyx/Work/testbeds/trysveltething/fullstack-sveltekit/node_modules/@supabase/supabase-js/src/index.ts'
Error: ENOENT: no such file or directory, open '/Users/swyx/Work/testbeds/trysveltething/fullstack-sveltekit/node_modules/@supabase/supabase-js/src/index.ts'
i have no idea where the /src/index.ts reference comes from, it doesnt show up in the module's package.json....
update: looks like it's getting it from the sourcemap https://github.com/sveltejs/kit/issues/673
FWIW - installing as a dev dependency seems to resolve the issue in my SvelteKit project: npm install -D @supabase/supabase-js
.
Instead of your import, maybe:
import _supabase from '@supabase/supabase-js';
const {createClient} = __supabase;
@mankins - unfortunately this doesn't seem to work, neither with supabase-js
as a dev dependency nor as a prod dependency.
I found this note in the SvelteKit FAQ which may be relevant:
question: How do I fix the error I'm getting trying to include a package?
Most of these issues come from Vite trying to deal with non-ESM libraries. You may find helpful examples in the Vite issue tracker. The most common solutions would be to try moving the package between
dependencies
anddevDependencies
or trying toinclude
orexclude
it inoptimizeDeps
. Packages which useexports
instead ofmodule.exports
are currently failing due to a known Vite issue. You should also consider asking the library author to distribute an ESM version of their package or even converting the source for the package entirely to ESM.You should also add any Svelte components to
ssr.noExternal
. We hope to do this automatically in the future by detecting thesvelte
field in a package'spackage.json
.
As suggested, I just tried to include
or exclude
@supabase/supabase-js
in optimizeDeps
in my svelte.config.cjs
under vite
but this not only didn't work for prod, it also broke the previously working npm run dev
.
That leads me to wonder if somewhere in the dependency tree, we need to ask some package maintainer to provide ESM support?
This bug report is old. It's from when SvelteKit was built on top of Snowpack. SvelteKit is now built on Vite and meriyah was removed as part of that transition: https://github.com/sveltejs/kit/pull/409. I can't find meriyah in the SvelteKit dependencies anymore. Can you make sure you're using the latest version of SvelteKit? If so, and there's still an issue, can you share the new stack trace?
Oh, nevermind. I see the comment above that there was a new error: https://github.com/supabase/supabase-js/issues/89#issuecomment-807151173. But then I'm really confused because the next message says it's been fixed: https://github.com/supabase/supabase-js/issues/89#issuecomment-809385143
I think we should probably file a new issue and close this one which has gotten quite muddled. I can't tell what issue exists if any
Yeah it seems a similar issue is happening in Vite; it has to do with the bundler managing a mixture of CSJ and ESM modules as far as I can tell. Someone mentioned this is a growing pain for these next generation build tools which leveral native ESM imports.
I'll try and draft a new issue on this topic today still; I'm collecting as much info as I can to elucidate it.
If you're using SvelteKit's adapter-node
or adapter-static
you can use the trick of putting Supabase in devDependencies
as a workaround. For everyone else I believe you will need Supabase's sourcemap to be fixed and this issue should be closed in favor of https://github.com/supabase/supabase-js/issues/153
OK #153 is resolved now 👍 . Let me know if this one can also be closed
Now that the sourcemap issue has been fixed we can see the real underlying error which is https://github.com/supabase/supabase-js/issues/155. I think this issue could be closed in favor of that one
Bug report
adding
into any script tag in a svelte project will cause a 500.
Describe the bug
I believe this has to do with svelte kit renders being executed on both the server side and client side. It also appears to be related to the javascript parser they use (meriyah). Starting the project, and opening a page containing the supabase import results in the following error:
To Reproduce
Steps to reproduce the behavior, please provide code snippets or a repository: repro repo: https://github.com/andykais/supabase-svelte-kit-bug-repro
npm install
npm run dev
http://localhost:3000
Expected behavior
supabase should ideally work in both the client and server environments of svelte kit.
Screenshots
N/A
System information
Additional context
Note: this is an error that is present in an experimental web framework. It is therefore likely a result of this project not being fully featured. Still, this feels like it is worth tracking.
I attempted dropping the supabase-js built files into the meriyah online compiler to see if the errors were visible there. However it appeared to compile the js code without any issue. There may be specific knobs that svelte kit has tweaked which cause the
Unexpected token
error, but I am unsure.