Skip to content

feat: resolve svelte to svelte/ssr when building for ssr (fixes #74) #75

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jul 8, 2021

Conversation

dominikg
Copy link
Member

Copy link
Member

@dummdidumm dummdidumm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know when that ssr parameter in the enhanced function is true (I guess when Vite builds the stuff for the Server output). Assuming it does what I think it does this looks good to me.

@dominikg
Copy link
Member Author

dominikg commented Jul 1, 2021

turns out you have to add svelte to ssr.noExternal in vite config for it to get passed through resolveId.

Adding it to the playground config results in the expected warning for a missing svelte/ssr export.

vite v2.3.8 building SSR bundle for production...
transforming (1) .svelte-kit/build/app.js[vite-plugin-svelte] failed to resolve svelte  to svelte/ssr
Error: Missing "./ssr" export in "svelte" package
    at bail (/home/dominikg/develop/sveltejs/vite-plugin-svelte/node_modules/.pnpm/vite@2.3.8/node_modules/vite/dist/node/chunks/dep-0ed4fbc0.js:32135:8)
    at resolve$1 (/home/dominikg/develop/sveltejs/vite-plugin-svelte/node_modules/.pnpm/vite@2.3.8/node_modules/vite/dist/node/chunks/dep-0ed4fbc0.js:32211:10)
    at resolveExports (/home/dominikg/develop/sveltejs/vite-plugin-svelte/node_modules/.pnpm/vite@2.3.8/node_modules/vite/dist/node/chunks/dep-0ed4fbc0.js:32640:12)
    at resolveDeepImport (/home/dominikg/develop/sveltejs/vite-plugin-svelte/node_modules/.pnpm/vite@2.3.8/node_modules/vite/dist/node/chunks/dep-0ed4fbc0.js:32657:26)
    at tryNodeResolve (/home/dominikg/develop/sveltejs/vite-plugin-svelte/node_modules/.pnpm/vite@2.3.8/node_modules/vite/dist/node/chunks/dep-0ed4fbc0.js:32446:11)
    at Object.resolveId (/home/dominikg/develop/sveltejs/vite-plugin-svelte/node_modules/.pnpm/vite@2.3.8/node_modules/vite/dist/node/chunks/dep-0ed4fbc0.js:32330:28)
    at Object.<anonymous> (/home/dominikg/develop/sveltejs/vite-plugin-svelte/node_modules/.pnpm/vite@2.3.8/node_modules/vite/dist/node/chunks/dep-0ed4fbc0.js:45595:33)
    at /home/dominikg/develop/sveltejs/vite-plugin-svelte/node_modules/.pnpm/rollup@2.52.4/node_modules/rollup/dist/shared/rollup.js:20008:25 {
  code: 'PLUGIN_ERROR',
  plugin: 'vite:resolve',
  hook: 'resolveId'
}

Question is, is that actually what kit wants to do? Or are there other ways to achieve this by using import.meta.env.SSR or $app/env ?

@dominikg
Copy link
Member Author

dominikg commented Jul 4, 2021

Cleaned it up a bit:

  • automatically add svelte to ssr.noExternal
  • less logging, inform user to update svelte (needed?)
  • testwith clientside dynamic import

To start the tests without all the others use
pnpm test:ci:build -- --testNamePattern=kit-node

@dominikg dominikg merged commit f6f56fe into main Jul 8, 2021
@dominikg dominikg deleted the feat/svelte-ssr branch July 8, 2021 09:01
@github-actions github-actions bot mentioned this pull request Jul 8, 2021
@github-actions github-actions bot mentioned this pull request Jul 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants