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

adapter-static error: new URL(url, import.meta.url) is not supported in SSR. even though SSR is disabled #2978

Closed
jquesada2016 opened this issue Dec 3, 2021 · 1 comment

Comments

@jquesada2016
Copy link

jquesada2016 commented Dec 3, 2021

Describe the bug

I am trying to integrate a rust wasm-pack generated WASM module with Svelte Kit. Everything works fine in dev. This is meant to be a SPA, so I have disabled SSR in svelte.config.js. It's only when building that I get an error. I do have the fallback option set, as well.

Reproduction

  1. Start a new empty SvelteKit project
  2. Copy the following svelte config file
    svelte.config.js
import adapter from "@sveltejs/adapter-static";
import preprocess from "svelte-preprocess";

/** @type {import('@sveltejs/kit').Config} */
const config = {
  // Consult https://github.com/sveltejs/svelte-preprocess
  // for more information about preprocessors
  preprocess: [
    preprocess({
      postcss: true,
    }),
  ],

  kit: {
    ssr: false,

    adapter: adapter({ fallback: "index.html" }),

    // hydrate the <div id="svelte"> element in src/app.html
    target: "#svelte",

    vite: {
      resolve: {
        alias: {
          $wasm: "/src/lib/wasm/pkg",
        },
      },
    },
  },
};

export default config;
  1. cd into /src/lib
  2. Run wasm-pack new wasm
  3. cd into new wasm folder
  4. Run wasm-pack build --target web --release
  5. cd back to the root of the SvelteKit project
  6. Add the following to /src/routes/__layout.svelte
<script lang="ts" context="module">
  // WASM
  import init from "$wasm";
  
  // Svelte
  import type { Load } from "@sveltejs/kit";

  export const load: Load = async () => {
    await init();

    return { status: 200 };
  }
</script>

<slot />
  1. Run npm run build
  2. watch the errors

Logs

> system@0.0.1 build
> svelte-kit build

vite v2.6.14 building for production...
transforming (4) src/routes/print-label/__layout.reset.svelte9:15:09 AM [vite-plugin-svelte] /home/joseprogdp/dev/commercial/USA Trade/system/src/routes/print-label/[id].svelte:12:36 'close' is not defined
10: </script>
11: 
12: <svelte:window on:afterprint={() => close()} />
                                        ^
13: 
14: {@html qrCode}
transforming (8) .svelte-kit/build/generated/manifest.js(node:6205) [DEP0148] DeprecationWarning: Use of deprecated folder mapping "./" in the "exports" field module resolution of the package at /home/joseprogdp/dev/commercial/USA Trade/system/node_modules/tslib/package.json.
Update this package.json to use a subpath pattern like "./*".
(Use `node --trace-deprecation ...` to show where the warning was created)
transforming (38) src/lib/firebase.config.ts9:15:10 AM [vite-plugin-svelte] /home/joseprogdp/dev/commercial/USA Trade/system/src/lib/components/dropdown.svelte:25:8 A11y: <a> element should have an href attribute
23:     {#each items as item, i}
24:       <li on:click={() => dispatch("click", { index: i, item })}>
25:         <a><slot name="item" {item} /></a>
            ^
26:       </li>
27:     {/each}
9:15:10 AM [vite-plugin-svelte] /home/joseprogdp/dev/commercial/USA Trade/system/src/lib/components/dropdown.svelte:5:11 Dropdown has unused export property 'hover'. If it is for external reference only, please consider using `export const hover`
3: // Props
4: export let placement = "bottom";
5: export let hover = false;
              ^
6: export let end = false;
7: export let items = [];
9:15:10 AM [vite-plugin-svelte] /home/joseprogdp/dev/commercial/USA Trade/system/src/lib/components/tooltip.svelte:3:11 Tooltip has unused export property 'open'. If it is for external reference only, please consider using `export const open`
1: <script lang="ts">// Props
2: export let tip;
3: export let open = false;
              ^
4: export let placement = "top";
5: export let kind = undefined;
9:15:10 AM [vite-plugin-svelte] /home/joseprogdp/dev/commercial/USA Trade/system/src/lib/components/tabs.svelte:16:6 A11y: '' is not a valid href attribute
14:   {#each tabs as tab, i}
15:     <a
16:       href=""
          ^
17:       class="tab"
18:       class:tab-active={i === activeTab}
9:15:10 AM [vite-plugin-svelte] /home/joseprogdp/dev/commercial/USA Trade/system/src/lib/components/tile.svelte:7:11 Tile has unused export property 'imageUrl'. If it is for external reference only, please consider using `export const imageUrl`
 5: export let price = undefined;
 6: export let href = undefined;
 7: export let imageUrl = "";
               ^
 8: </script>
 9: 
transforming (50) src/lib/components/textarea.svelte
🌼 daisyUI components 1.16.2  https://github.com/saadeghi/daisyui
  ✔︎ Including:  base, components, themes[22], utilities
  

🌼 daisyUI components 1.16.2  https://github.com/saadeghi/daisyui
  ✔︎ Including:  base, components, themes[22], utilities
  
✓ 55 modules transformed.
.svelte-kit/output/client/_app/assets/wasm_bg-994dcdb4.wasm                          134.91 KiB
.svelte-kit/output/client/_app/manifest.json                                         3.20 KiB
.svelte-kit/output/client/_app/pages/__layout.svelte-8384ae74.js                     3.16 KiB / gzip: 1.62 KiB
.svelte-kit/output/client/_app/error.svelte-56d68a3b.js                              1.56 KiB / gzip: 0.75 KiB
.svelte-kit/output/client/_app/pages/print-label/__layout.reset.svelte-156cdc52.js   0.72 KiB / gzip: 0.45 KiB
.svelte-kit/output/client/_app/start-868c57cb.js                                     19.53 KiB / gzip: 7.06 KiB
.svelte-kit/output/client/_app/pages/print-label/_id_.svelte-72b67461.js             0.99 KiB / gzip: 0.56 KiB
.svelte-kit/output/client/_app/pages/sign-in.svelte-b75cb3c1.js                      1.43 KiB / gzip: 0.80 KiB
.svelte-kit/output/client/_app/chunks/singletons-12a22614.js                         0.05 KiB / gzip: 0.06 KiB
.svelte-kit/output/client/_app/pages/index.svelte-00915e92.js                        22.69 KiB / gzip: 7.28 KiB
.svelte-kit/output/client/_app/chunks/button-be083e4d.js                             3.91 KiB / gzip: 1.46 KiB
.svelte-kit/output/client/_app/chunks/navigation-51f4a605.js                         0.11 KiB / gzip: 0.12 KiB
.svelte-kit/output/client/_app/assets/start-464e9d0a.css                             0.19 KiB / gzip: 0.15 KiB
.svelte-kit/output/client/_app/chunks/wasm-68f6d283.js                               11.59 KiB / gzip: 3.74 KiB
.svelte-kit/output/client/_app/assets/pages/__layout.svelte-99146126.css             59.12 KiB / gzip: 9.63 KiB
.svelte-kit/output/client/_app/chunks/vendor-50d652a9.js                             437.63 KiB / gzip: 104.47 KiB
vite v2.6.14 building SSR bundle for production...
transforming (1) .svelte-kit/build/app.js9:15:13 AM [vite-plugin-svelte] /home/joseprogdp/dev/commercial/USA Trade/system/src/routes/print-label/[id].svelte:12:36 'close' is not defined
10: </script>
11: 
12: <svelte:window on:afterprint={() => close()} />
                                        ^
13: 
14: {@html qrCode}
✓ 15 modules transformed.
[vite:asset-import-meta-url] `new URL(url, import.meta.url)` is not supported in SSR.
file: /home/joseprogdp/dev/commercial/USA Trade/system/src/lib/wasm/pkg/wasm.js:534:16
532: async function init(input) {
533:     if (typeof input === 'undefined') {
534:         input = new URL('wasm_bg.wasm', import.meta.url);
                     ^
535:     }
536:     const imports = {};
> `new URL(url, import.meta.url)` is not supported in SSR.
Error: `new URL(url, import.meta.url)` is not supported in SSR.
    at error (/home/joseprogdp/dev/commercial/USA Trade/system/node_modules/rollup/dist/shared/rollup.js:158:30)
    at throwPluginError (/home/joseprogdp/dev/commercial/USA Trade/system/node_modules/rollup/dist/shared/rollup.js:21793:12)
    at Object.error (/home/joseprogdp/dev/commercial/USA Trade/system/node_modules/rollup/dist/shared/rollup.js:22497:20)
    at Object.error (/home/joseprogdp/dev/commercial/USA Trade/system/node_modules/rollup/dist/shared/rollup.js:21969:38)
    at Object.transform (/home/joseprogdp/dev/commercial/USA Trade/system/node_modules/vite/dist/node/chunks/dep-e0fe87f8.js:42802:30)
    at Object.<anonymous> (/home/joseprogdp/dev/commercial/USA Trade/system/node_modules/vite/dist/node/chunks/dep-e0fe87f8.js:43315:19)

System Info

System: `WSL2` running on `Windows 11`.
NodeJS Version: v16.9.1
SvelteKit Version: Latest
adapter-static Version: Latest

Severity

blocking all usage of SvelteKit

Additional Information

No response

@benmccann
Copy link
Member

duplicate of #1896

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

No branches or pull requests

2 participants