Skip to content
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

Dynamic import fails in route with template parameters or (group) #8516

Closed
Oreilles opened this issue Jan 13, 2023 · 3 comments
Closed

Dynamic import fails in route with template parameters or (group) #8516

Oreilles opened this issue Jan 13, 2023 · 3 comments
Labels

Comments

@Oreilles
Copy link
Contributor

Oreilles commented Jan 13, 2023

Describe the bug

Dynamically importing a module in a route with parameters or (group), for example:

// src/routes/[foo]/+page.js
export async load = ({ params }) => (await import(`./index.${params.foo}.js`).data;


// src/routes/(foo)/bar/+page.js
export async load = ({ url }) => (await import(`./index.${url.params.get('foo'}.js`).data;

Fails with the following error:

Error: Unknown variable dynamic import: ../[foo]/index.foo.js
    at vite/dynamic-import-helper:7:96
    at new Promise (<anonymous>)
    at __vite_ssr_exports__.default (vite/dynamic-import-helper:6:12)
    at load (/src/routes/[foo]/+page.js:2:59)
    at Module.load_data (/node_modules/@sveltejs/kit/src/runtime/server/page/load_data.js:110:43)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async eval (/node_modules/@sveltejs/kit/src/runtime/server/page/index.js:195:13)

Related: #8490

Reproduction

https://stackblitz.com/edit/sveltejs-kit-template-default-peg2jd?file=src/routes/[foo]/+page.js

Logs

No response

System Info

System:
    OS: macOS 13.0.1
    CPU: (8) arm64 Apple M1
    Memory: 62.50 MB / 8.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 18.11.0 - /opt/homebrew/bin/node
    Yarn: 1.22.19 - /opt/homebrew/bin/yarn
    npm: 8.19.2 - /opt/homebrew/bin/npm
  Browsers:
    Brave Browser: 108.1.46.153
    Firefox: 108.0.2
    Safari: 16.1
  npmPackages:
    @sveltejs/adapter-auto: ^1.0.0 => 1.0.0
    @sveltejs/kit: ^1.0.0 => 1.0.13
    svelte: ^3.54.0 => 3.55.1
    vite: ^4.0.0 => 4.0.4

Severity

serious, but I can work around it

Additional Information

No response

@Oreilles Oreilles changed the title Dynamic import fails in route with template parameters Dynamic import fails in route with template parameters or (group) Jan 14, 2023
@dummdidumm
Copy link
Member

@bluwy sounds like an upstream issue with Vite?

@bluwy
Copy link
Member

bluwy commented Jan 16, 2023

Hmm yeah I think this could be a Vite bug. I remember (, ), +, etc being in the paths were already fixed, but maybe we weren't handling it right still. If this can be reproduced with https://stackblitz.com/fork/github/bluwy/create-vite-extra/tree/master/template-ssr-svelte (or the vanilla variant), it would be great to report this to Vite.

@Rich-Harris
Copy link
Member

It's definitely a Vite issue. I've added a SvelteKit-less repro to vitejs/vite#11824, will close this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants