1

When I try to deploy a SvelteKit app with supabase to Netlify (using adapter-netlify), the Netlify build fails with the following error:

requested module '@supabase/supabase-js' does not provide an export named 'createClient'

However, I can succesfully npm run build locally without any errors.

I've also tried reinstalling supabase and updating all my npm packages, and switching the supabase package between dependencies and devDependencies, but the Netlify builds are still failing.

When building on Netlify, here are the failing deployment logs:

 npm run build
7:54:27 PM: > [email protected] build /opt/build/repo
7:54:27 PM: > svelte-kit build
7:54:27 PM: (node:1389) ExperimentalWarning: The ESM module loader is experimental.
7:54:27 PM: vite v2.3.3 building for production...
7:54:28 PM: transforming...
7:54:42 PM: ✓ 96 modules transformed.
7:54:43 PM: rendering chunks...
7:54:59 PM: .svelte-kit/output/client/_app/manifest.json                               1.64kb
7:54:59 PM: .svelte-kit/output/client/_app/pages/index.svelte-cada8c67.js              0.14kb / brotli: 0.10kb
7:54:59 PM: .svelte-kit/output/client/_app/pages/__error.svelte-f4fa4b22.js            0.14kb / brotli: 0.10kb
7:54:59 PM: .svelte-kit/output/client/_app/chunks/singletons-bb9012b7.js               0.05kb / brotli: 0.05kb
7:54:59 PM: .svelte-kit/output/client/_app/pages/[slug].svelte-ec1023d5.js             0.14kb / brotli: 0.10kb
7:54:59 PM: .svelte-kit/output/client/_app/assets/start-0826e215.css                   0.18kb / brotli: 0.11kb
7:54:59 PM: .svelte-kit/output/client/_app/assets/vendor-119c9bb3.css                  7.66kb / brotli: 1.55kb
7:54:59 PM: .svelte-kit/output/client/_app/start-1a95caf6.js                           17.58kb / brotli: 5.58kb
7:54:59 PM: .svelte-kit/output/client/_app/pages/__layout.svelte-9141578b.js           49.85kb / brotli: 12.14kb
7:54:59 PM: .svelte-kit/output/client/_app/assets/pages/__layout.svelte-85885be8.css   86.98kb / brotli: 12.04kb
7:54:59 PM: .svelte-kit/output/client/_app/chunks/vendor-b335e5ae.js                   843.03kb / brotli: skipped (large chunk)
7:54:59 PM: 
7:54:59 PM: (!) Some chunks are larger than 500kb after minification. Consider:
7:54:59 PM: - Using dynamic import() to code-split the application
7:54:59 PM: - Use build.rollupOptions.output.manualChunks to improve chunking: https://rollupjs.org/guide/en/#outputmanualchunks
7:54:59 PM: - Adjust chunk size limit for this warning via build.chunkSizeWarningLimit.
7:54:59 PM: vite v2.3.3 building SSR bundle for production...
7:54:59 PM: transforming...
7:55:05 PM: ✓ 41 modules transformed.
7:55:05 PM: rendering chunks...
7:55:05 PM: .svelte-kit/output/server/app.js   286.21kb
7:55:05 PM: Run npm run preview to preview your production build locally.
7:55:05 PM: 
7:55:05 PM: > Using @sveltejs/adapter-netlify
7:55:05 PM: > The requested module '@supabase/supabase-js' does not provide an export named 'createClient'
7:55:05 PM: file:///opt/build/repo/.svelte-kit/output/server/app.js:5
7:55:05 PM: import {createClient} from "@supabase/supabase-js";
7:55:05 PM:         ^^^^^^^^^^^^
7:55:05 PM: SyntaxError: The requested module '@supabase/supabase-js' does not provide an export named 'createClient'
7:55:05 PM:     at ModuleJob._instantiate (internal/modules/esm/module_job.js:92:21)
7:55:05 PM:     at async ModuleJob.run (internal/modules/esm/module_job.js:107:20)
7:55:05 PM:     at async Loader.import (internal/modules/esm/loader.js:179:24)
7:55:05 PM:     at async prerender (file:///opt/build/repo/node_modules/@sveltejs/kit/dist/chunks/index5.js:79:14)
7:55:05 PM:     at async Object.prerender (file:///opt/build/repo/node_modules/@sveltejs/kit/dist/chunks/index5.js:296:5)
7:55:05 PM:     at async adapt (file:///opt/build/repo/node_modules/@sveltejs/adapter-netlify/index.js:33:4)
7:55:05 PM:     at async adapt (file:///opt/build/repo/node_modules/@sveltejs/kit/dist/chunks/index5.js:322:2)
7:55:05 PM:     at async file:///opt/build/repo/node_modules/@sveltejs/kit/dist/cli.js:616:5
7:55:05 PM: npm ERR! code ELIFECYCLE
7:55:05 PM: npm ERR! errno 1
7:55:05 PM: npm ERR! [email protected] build: `svelte-kit build`
7:55:05 PM: npm ERR! Exit status 1
7:55:05 PM: npm ERR!
7:55:05 PM: npm ERR! Failed at the [email protected] build script.
7:55:05 PM: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
7:55:05 PM: npm ERR! A complete log of this run can be found in:
7:55:05 PM: npm ERR!     /opt/buildhome/.npm/_logs/2021-05-18T17_55_05_631Z-debug.log
7:55:05 PM: ​
7:55:05 PM: ────────────────────────────────────────────────────────────────
7:55:05 PM:   "build.command" failed                                        
7:55:05 PM: ────────────────────────────────────────────────────────────────
7:55:05 PM: ​
7:55:05 PM:   Error message
7:55:05 PM:   Command failed with exit code 1: npm run build
7:55:05 PM: ​
7:55:05 PM:   Error location
7:55:05 PM:   In build.command from netlify.toml:
7:55:05 PM:   npm run build
7:55:05 PM: ​
7:55:05 PM:   Resolved config
7:55:05 PM:   build:
7:55:05 PM:     command: npm run build
7:55:05 PM:     commandOrigin: config
7:55:05 PM:     publish: /opt/build/repo/build
7:55:05 PM:   functionsDirectory: /opt/build/repo/functions
7:55:06 PM: Caching artifacts
7:55:06 PM: Started saving node modules
7:55:06 PM: Finished saving node modules
7:55:06 PM: Started saving build plugins
7:55:06 PM: Finished saving build plugins
7:55:06 PM: Started saving pip cache
7:55:06 PM: Finished saving pip cache
7:55:06 PM: Started saving emacs cask dependencies
7:55:06 PM: Finished saving emacs cask dependencies
7:55:06 PM: Started saving maven dependencies
7:55:06 PM: Finished saving maven dependencies
7:55:06 PM: Started saving boot dependencies
7:55:06 PM: Finished saving boot dependencies
7:55:06 PM: Started saving rust rustup cache
7:55:06 PM: Finished saving rust rustup cache
7:55:06 PM: Started saving go dependencies
7:55:06 PM: Finished saving go dependencies
7:55:08 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
7:55:08 PM: Creating deploy upload records
7:55:08 PM: Failing build: Failed to build site
7:55:08 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2
7:55:08 PM: Finished processing build request in 1m6.448211496s

Can anybody advise a fix?

1 Answer 1

1

This answer might differ based on which version of SvelteKit you have.

Try to add the following to svelte.config.js:

import preprocess from 'svelte-preprocess'
import adapterNetlify from '@sveltejs/adapter-netlify'
const dev = process.env.NODE_ENV === 'development'

/** @type {import('@sveltejs/kit').Config} */
const config = {
    preprocess: preprocess(),
    kit: {
        adapter: adapterNetlify(),
        target: '#svelte',
        vite: {
            ssr: {
                noExternal: dev ? [] : ['@supabase/supabase-js']
            },
        }
    }
};

export default config

For more info see:

https://github.com/vitejs/vite/issues/2579

https://github.com/sveltejs/kit/issues/904

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.