Hi~ I am a developer in South Korea. I am not good at english yet. But I have a question about SvelteKit.
I wrote the below codes in +page.svelte
as SvelteKit tutorial.
This code worked well in local dev mode.
<script>
import { env } from $env/dynamic/public ;
</script>
<main style:background={env.PUBLIC_THEME_BACKGROUND} style:color={env.PUBLIC_THEME_FOREGROUND}>
{env.PUBLIC_THEME_FOREGROUND} on {env.PUBLIC_THEME_BACKGROUND}
</main>
.....
Then I deployed the above codes to Vercel, build and published. But I got some error that is
undefined
in import { env } from $env/dynamic/public
Other codes of the SvelteKit tutorial which was deployed to Vercel worked well except this code.
That is, This error is not problem of the adapter or runtime of Vercel. Ok, I already changed them but could not fix this error.
因此,我设立了<代码>+page.server.ts文档,我将上述代码移至下文。
import { env } from $env/dynamic/public ;
export function load() {
return { env: {
PUBLIC_THEME_BACKGROUND: env.PUBLIC_THEME_BACKGROUND,
PUBLIC_THEME_FOREGROUND: env.PUBLIC_THEME_FOREGROUND,
}};
}
我将标记文档(+page.svelte
)修改如下。
<script>
export let data;
</script>
<main style:background={data.env.PUBLIC_THEME_BACKGROUND} style:color={data.env.PUBLIC_THEME_FOREGROUND}>
{data.env.PUBLIC_THEME_FOREGROUND} on {data.env.PUBLIC_THEME_BACKGROUND}
</main>
.....
现在, 该法典运作良好。 简言之,为什么不能打上<条码>美元/动力/公共条码>。 在Vercel的标记档案中工作?
- Changed the adapter of Vercel in
svelte.config.js
fromedge
tonodejsXXX
. - Changed the build script in
package.json
fromvite build
tomv ./env.local to ./.env && vite build
and remove.env
from.gitignore
. - Set up Vercel s environment variables in Project Settings.