1

当我尝试将带有 supbase 的 SvelteKit 应用程序部署到 Netlify(使用适配器-netlify)时,Netlify 构建失败并出现以下错误:

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

但是,我可以npm run build在本地成功,没有任何错误。

我还尝试过重新安装 supabase 并更新我所有的 npm 包,并在dependencies和之间切换 supabase 包devDependencies,但 Netlify 构建仍然失败。

在 Netlify 上构建时,以下是失败的部署日志:

 npm run build
7:54:27 PM: > ~TODO~@0.0.1 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! ~TODO~@0.0.1 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 ~TODO~@0.0.1 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

任何人都可以建议修复吗?

4

1 回答 1

1

这个答案可能会根据您拥有的 SvelteKit 版本而有所不同。

尝试将以下内容添加到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

有关更多信息,请参阅:

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

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

于 2021-05-25T19:27:39.410 回答