svelte-adapter-deno icon indicating copy to clipboard operation
svelte-adapter-deno copied to clipboard

SvelteKit update breaks deno-adapter

Open xkpx64 opened this issue 2 years ago • 13 comments

`[WARNING] Import "dirname" will always be undefined because the file ".svelte-kit/deno/deps.ts" has no exports [import-is-undefined]

.svelte-kit/deno/index.js:1:9:
  1 │ import { dirname, fromFileUrl, join, exists, Application } from './deps.ts';
    ╵          ~~~~~~~

▲ [WARNING] Import "fromFileUrl" will always be undefined because the file ".svelte-kit/deno/deps.ts" has no exports [import-is-undefined]

.svelte-kit/deno/index.js:1:18:
  1 │ import { dirname, fromFileUrl, join, exists, Application } from './deps.ts';

.svelte-kit/deno/index.js:1:37:
  1 │ import { dirname, fromFileUrl, join, exists, Application } from './deps.ts';
    ╵                                      ~~~~~~

▲ [WARNING] Import "Application" will always be undefined because the file ".svelte-kit/deno/deps.ts" has no exports [import-is-undefined]

.svelte-kit/deno/index.js:1:45:
  1 │ import { dirname, fromFileUrl, join, exists, Application } from './deps.ts';
    ╵                                              ~~~~~~~~~~~

PS C:\Users\Administrator\Desktop\x> pnpm run deno

x@ deno C:\Users\Administrator\Desktop\x deno run --allow-env --allow-read --allow-net xbuild_deno/index.js

error: Uncaught TypeError: (void 0) is not a function var __dirname = (void 0)((void 0)(import.meta.url)); ^ at file:///C:/Users/Administrator/Desktop/x/xbuild_deno/index.js:3540:34  ELIFECYCLE  Command failed with exit code 1. `

xkpx64 avatar Jul 06 '22 11:07 xkpx64

@xkpx64 thank you for reporting this, I'll take a look. Saw a few changes mentioned in the latest https://svelte.dev/blog/whats-new-in-svelte-july-2022 but still need to update the adapter to match them.

jpaquim avatar Jul 06 '22 12:07 jpaquim

Great to hear to you Sir, much love from me for your hard work with this project <3

xkpx64 avatar Jul 07 '22 09:07 xkpx64

Any chance of an update? I took a look at trying to fix this myself but I'm out of my depth :)

bradleyg avatar Sep 11 '22 11:09 bradleyg

@bradleyg Thanks for giving it a try, I'll take a look this week, I've been waiting for SvelteKit and Deno to stabilize a bit further, given the amount of changes in the last couple of months.

jpaquim avatar Sep 13 '22 09:09 jpaquim

Hey @xkpx64 and @bradleyg can you check if you still have the issue after updating to the latest version of this package? I updated it to work with latest SvelteKit (and other deps as well), but let me know if you're still having the same issue.

jpaquim avatar Sep 20 '22 19:09 jpaquim

This week I will confirm thanks sir

xkpx64 avatar Sep 21 '22 05:09 xkpx64

i'm finding that with the latest versions of each i'm just getting that deps.ts doesn't exist.

> Using svelte-adapter-deno
✘ [ERROR] Could not resolve "./deps.ts"

    .svelte-kit/deno/index.js:1:64:
      1 │ import { dirname, fromFileUrl, join, exists, Application } from './deps.ts';
        ╵                                                                 ~~~~~~~~~~~

osdiab avatar Sep 24 '22 06:09 osdiab

@osdiab I could not reproduce your error, are you using a custom deps.ts? Is there a minimal reproduction you could share?

jpaquim avatar Sep 25 '22 11:09 jpaquim

Ah sorry i removed the example code in the README that tells you to explicitly set the deps config and now it doesn't error with that. But instead getting this:

✘ [ERROR] Could not resolve "set-cookie-parser"

    .svelte-kit/output/server/index.js:5:35:
      5 │ import * as set_cookie_parser from "set-cookie-parser";
        ╵                                    ~~~~~~~~~~~~~~~~~~~

  The "main" field here was ignored. Main fields must be configured explicitly when using the
  "neutral" platform.

    node_modules/set-cookie-parser/package.json:15:2:
      15 │   "main": "./lib/set-cookie.js",
         ╵   ~~~~~~

  You can mark the path "set-cookie-parser" as external to exclude it from the bundle, which will
  remove this error.

error during build:
Error: Build failed with 1 error:
.svelte-kit/output/server/index.js:5:35: ERROR: Could not resolve "set-cookie-parser"
    at failureErrorWithLog (/Users/omardiab/code/sandbox/svelte-sandbox/node_modules/esbuild/lib/main.js:1566:15)
    at /Users/omardiab/code/sandbox/svelte-sandbox/node_modules/esbuild/lib/main.js:1024:28
    at /Users/omardiab/code/sandbox/svelte-sandbox/node_modules/esbuild/lib/main.js:969:67
    at buildResponseToResult (/Users/omardiab/code/sandbox/svelte-sandbox/node_modules/esbuild/lib/main.js:1022:7)
    at /Users/omardiab/code/sandbox/svelte-sandbox/node_modules/esbuild/lib/main.js:1134:14
    at responseCallbacks.<computed> (/Users/omardiab/code/sandbox/svelte-sandbox/node_modules/esbuild/lib/main.js:671:9)
    at handleIncomingPacket (/Users/omardiab/code/sandbox/svelte-sandbox/node_modules/esbuild/lib/main.js:726:9)
    at Socket.readFromStdout (/Users/omardiab/code/sandbox/svelte-sandbox/node_modules/esbuild/lib/main.js:647:7)
    at Socket.emit (node:events:527:28)
    at addChunk (node:internal/streams/readable:324:12)

osdiab avatar Sep 26 '22 00:09 osdiab

@osdiab ok so it seems you're trying to consume the dependency directly from npm/node_modules. Can you maybe try using esm.sh instead? For that package, the URL would be: https://esm.sh/[email protected]

jpaquim avatar Sep 26 '22 08:09 jpaquim

I don't directly consume it, I've literally just made a fresh sveltekit project and dropped in the deno adapter - should I be making my own deps.ts file then? Thanks!

osdiab avatar Sep 26 '22 23:09 osdiab

Ah, my bad, I thought you were adding the dependency in your project, but it seems to be one of SvelteKit's deps. Do you see any difference between your example and https://github.com/pluvial/svelte-adapter-deno/tree/main/examples/svelte-kit-demo ? That one was made by just creating a new SvelteKit application with the full template, and replacing the adapter-auto with the adapter-deno...

jpaquim avatar Sep 27 '22 08:09 jpaquim

Same problem : )

image

lost22git avatar Oct 11 '22 14:10 lost22git

this works, despite a little bit hackish:

  • install esbuild-plugin-replace, and add it to your svelte.config.js
import { replace } from 'esbuild-plugin-replace';
  • and in the adapter:
adapter: adapter({
  esbuild(defaultOptions) {
    return {
      ...defaultOptions,
      external: ['set-cookie-parser'],
      plugins: [
        replace({
          'set-cookie-parser': 'https://esm.sh/[email protected]',
        }),
      ],
    };
  },
});

widyakumara avatar Oct 20 '22 11:10 widyakumara

@osdiab @lost22git @widyakumara could you maybe provide a minimal reproduction of the issue? I've been unable to reproduce it, here is a vanilla sveltekit app using svelte-adapter-deno, if you want to test locally: https://github.com/jpaquim/sveltekit-deno-app

jpaquim avatar Oct 20 '22 13:10 jpaquim

Ok, after seeing the yarn-related messages, I got a hunch that the difference might be related to differences in package manager, and alas, it seems to be working well only using pnpm, but not using either npm or yarn... I'll try to understand why that is...

jpaquim avatar Oct 20 '22 13:10 jpaquim

Ok, I think changing the platform to "browser" seems to have fixed it. I merged the changes in https://github.com/pluvial/svelte-adapter-deno/pull/31 Can you try updating to svelte-adapter-deno version 0.8.0 and see if your problem is fixed?

jpaquim avatar Oct 20 '22 14:10 jpaquim

@jpaquim yup the problem is fixed (using svelte-adapter-deno 0.8.1) and i can confirm it's deployable to deno deploy 🎉

thank you!

widyakumara avatar Oct 20 '22 15:10 widyakumara

Thank you for the feedback @widyakumara! I'll close this issue, I'll reopen it if it keeps affecting anyone else.

jpaquim avatar Oct 20 '22 16:10 jpaquim