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

Deno 2 compile doesn't work on sveltekit (error: Module not found runtime/control.js) #26155

Open
SerJaimeLannister opened this issue Oct 11, 2024 · 31 comments
Labels
bug Something isn't working correctly compile related to the `deno compile` feature

Comments

@SerJaimeLannister
Copy link

SerJaimeLannister commented Oct 11, 2024

Version: deno 2.0.0 (stable, release, x86_64-unknown-linux-gnu) (archlinux)
v8 12.9.202.13-rusty
typescript 5.6.2

Running deno compile on a sveltekit app returns a Module not found runtime/control.js error.

Steps to reproduce

  1. Run deno -A npm:create-svelte@latest my-app
    1.1. Click on Sveltekit demo app
    1.2. Yes using typescript syntax
    1.3. Selecting all the 5 options presented in the next step using space bar ) (Add eslint , prettier , vitest etc.)
  2. Run cd my-app
  3. Run deno install
  4. Run deno run dev (shows the expected sveltekit demo app at localhost:5173)
  5. Run deno install npm:svelte-adapter-deno
  6. Update svelte.config.js file to use Deno adapter:
// svelte.config.js
import adapter from 'svelte-adapter-deno';

export default {
  kit: {
    adapter: adapter()
  }
};
  1. Run deno run build to produce build folder and then cd into it (interestingly the last time I ran this it produced a mod.ts file but this time it didn't produce mod.ts I am not exactly sure what has changed since the last time) (this is extremely weird)
  2. but still running deno run index.js and giving it the permissions runs the sveltekit demo app
  3. Run deno compile build/server/index.js

Output:

error: Module not found "file:///home/test/Projects/deno/my-app/build/runtime/control.js".
    at file:///home/test/Projects/deno/my-app/build/server/index.js:1345:23
@SerJaimeLannister SerJaimeLannister changed the title Deno 2 compile doesn't work on sveltekit Deno 2 compile doesn't work on sveltekit Oct 11, 2024
@SerJaimeLannister SerJaimeLannister changed the title Deno 2 compile doesn't work on sveltekit Deno 2 compile doesn't work on sveltekit (error: Module not found runtime/control.js) Oct 11, 2024
@marvinhagemeister marvinhagemeister added bug Something isn't working correctly compile related to the `deno compile` feature labels Oct 11, 2024
@uncomfyhalomacro
Copy link
Contributor

uncomfyhalomacro commented Oct 12, 2024

@SerJaimeLannister may i ask if that's really all the content of your file svelte.config.js?

@uncomfyhalomacro
Copy link
Contributor

Okay. I was able to reproduce. Mine is also looking for my-app/build/runtime/control.js hmm

@uncomfyhalomacro
Copy link
Contributor

I find this really weird to be honest. see screenshot below

commands used

  • bonk a touch+mkdir utility

image

@uncomfyhalomacro
Copy link
Contributor

uncomfyhalomacro commented Oct 12, 2024

Update: I have a feeling it's looking for this???? (see terminal right)

image

@SerJaimeLannister
Copy link
Author

Were you able to fix this @uncomfyhalomacro

@uncomfyhalomacro
Copy link
Contributor

uncomfyhalomacro commented Oct 12, 2024

Were you able to fix this @uncomfyhalomacro

Nope. but i found out how to "make it run". Here is what I did

  1. cp -rf '/home/uncomfy/development/projects/.cache/deno/npm/registry.npmjs.org/@sveltejs/kit/2.7.0/src/runtime' runtime
  2. cp /home/uncomfy/development/projects/.cache/deno/npm/registry.npmjs.org/svelte-eslint-parser/0.41.1/lib/parser/typescript/types.js server/types.js
  3. mkdir -p server page && cp /home/uncomfy/development/projects/.cache/deno/npm/registry.npmjs.org/svelte-eslint-parser/0.41.1/lib/parser/typescript/types.js server/page/types.js
  4. deno compila -A index.js && ./build

image

It's kind of broken but it's also beyond my abilities.

@uncomfyhalomacro
Copy link
Contributor

Nearly was able to. now time to sleep
image
image

@SerJaimeLannister
Copy link
Author

SerJaimeLannister commented Oct 13, 2024

Hmm , this is kind of "good enough support" and though I appreciate your efforts , I don't think this is worth enough to close this issue

Hopefully someone from the deno team can fix this completely

@yazan-abdalrahman
Copy link
Contributor

I found the main issue and opened a new ticket (#26233) to make it easier to reproduce. So, we can close this and proceed with the new (#26233).

You can do some workarounds for this issue. Go into index.js and remove each JSDoc comments with @param and import(...)statement (e.g., @param {import('./page/types.js').Cookie['options']})

That will make the compile successful.

@SerJaimeLannister
Copy link
Author

I found the main issue and opened a new ticket (#26233) to make it easier to reproduce. So, we can close this and proceed with the new (#26233).

You can do some workarounds for this issue. Go into index.js and remove each JSDoc comments with @param and import(...)statement (e.g., @param {import('./page/types.js').Cookie['options']})

That will make the compile successful.

Hey so I did try to remove the as a workaround and it still doesn't work , do I need to remove this jsdoc comment + import on each file of my project?

@yazan-abdalrahman
Copy link
Contributor

jsdoc comment + import on
I removed each '@param {import(' from 'build/server/index.js' and it worked when I compiled it.

@yazan-abdalrahman
Copy link
Contributor

yazan-abdalrahman commented Oct 15, 2024

Oh, I found a solution. It's not a bug.

Use --no-check in compile to skip checking the jsdoc.

deno compile --no-check build/server/index.js

@dsherret @bartlomieju

@SerJaimeLannister
Copy link
Author

deno compile --no-check build/server/index.js

hey just a minor nitpick , we don't need to have this for build/server/index.js but rather build/index.js

also when I reload , it actually shows asset to be a 404 for some time but just going to a different page makes it work , its very bizarre to say the least and actually gives this error

Error: Not found: /
    at resolve2 (file:///tmp/deno-compile-build/my-app/build/server/index.js:4831:18)
    at resolve (file:///tmp/deno-compile-build/my-app/build/server/index.js:4664:34)
    at Object.handle (file:///tmp/deno-compile-build/my-app/build/server/index.js:4896:71)
    at respond (file:///tmp/deno-compile-build/my-app/build/server/index.js:4662:43)
    at eventLoopTick (ext:core/01_core.js:175:7) {
  status: 404,
  text: "Not Found"
}
sveltekit-test.mp4

@SerJaimeLannister
Copy link
Author

Also I think deno should give a warning / custom flag that hey you should do --no-check like how it does for --unstable-sloppy-imports and even then as in the recent issue by @marvinhagemeister (I know this is amature but I tried looking for the issue but I couldn't find the issue created by marvin for --unstable-sloppy-imports) but If I remember correctly it was about asking at the runtime to enable unstable-sloppy-imports.

I think something like this should also be done with deno compile --no-check

also , fixing the issue as of the video could be of some priority

@yazan-abdalrahman
Copy link
Contributor

Version: deno 2.0.0 (stable, release, x86_64-unknown-linux-gnu) (archlinux) v8 12.9.202.13-rusty typescript 5.6.2

Running deno compile on a sveltekit app returns a Module not found runtime/control.js error.

Steps to reproduce

  1. Run deno -A npm:create-svelte@latest my-app
    1.1. Click on Sveltekit demo app
    1.2. Yes using typescript syntax
    1.3. Selecting all the 5 options presented in the next step using space bar ) (Add eslint , prettier , vitest etc.)
  2. Run cd my-app
  3. Run deno install
  4. Run deno run dev (shows the expected sveltekit demo app at localhost:5173)
  5. Run deno install npm:svelte-adapter-deno
  6. Update svelte.config.js file to use Deno adapter:
// svelte.config.js
import adapter from 'svelte-adapter-deno';

export default {
  kit: {
    adapter: adapter()
  }
};
  1. Run deno run build to produce build folder and then cd into it (interestingly the last time I ran this it produced a mod.ts file but this time it didn't produce mod.ts I am not exactly sure what has changed since the last time) (this is extremely weird)
  2. but still running deno run index.js and giving it the permissions runs the sveltekit demo app
  3. Run deno compile build/server/index.js

Output:

error: Module not found "file:///home/test/Projects/deno/my-app/build/runtime/control.js".
    at file:///home/test/Projects/deno/my-app/build/server/index.js:1345:23

I thought your issue in compile (step 9) gives you this error.

error: Module not found "file:///home/test/Projects/deno/my-app/build/runtime/control.js".
    at file:///home/test/Projects/deno/my-app/build/server/index.js:1345:23

and that is mentioned on the label of bug compile

So, to get build without error module not found (that's error occurs in import in commented JSdoc, it's not bug), use --no-check with the compile command

@yazan-abdalrahman
Copy link
Contributor

Also I think deno should give a warning / custom flag that hey you should do --no-check like how it does for --unstable-sloppy-imports and even then as in the recent issue by @marvinhagemeister (I know this is amature but I tried looking for the issue but I couldn't find the issue created by marvin for --unstable-sloppy-imports) but If I remember correctly it was about asking at the runtime to enable unstable-sloppy-imports.

I think something like this should also be done with deno compile --no-check

also , fixing the issue as of the video could be of some priority

I thought an outside bug was the major issue in compile, which was resolved with --no-check.

@yazan-abdalrahman
Copy link
Contributor

@dsherret

@SerJaimeLannister
Copy link
Author

oh I see I have to admit my mistake here
to compile the sveltekit project we need to actually build by changing the adapter
and then compiling build/index.js should atleast make it work though with some issues (instead of build/server/index.js) (this was my first time writing reproducible bug so I am sorry )

@SerJaimeLannister
Copy link
Author

SerJaimeLannister commented Oct 15, 2024

@yazan-abdalrahman please check the video that I provided , it shows this error

Error: Not found: /
    at resolve2 (file:///tmp/deno-compile-build/my-app/build/server/index.js:4831:18)
    at resolve (file:///tmp/deno-compile-build/my-app/build/server/index.js:4664:34)
    at Object.handle (file:///tmp/deno-compile-build/my-app/build/server/index.js:4896:71)
    at respond (file:///tmp/deno-compile-build/my-app/build/server/index.js:4662:43)
    at eventLoopTick (ext:core/01_core.js:175:7) {
  status: 404,
  text: "Not Found"
}

(this seems a very interesting thing as to why it shows this error )

@yazan-abdalrahman
Copy link
Contributor

yazan-abdalrahman commented Oct 15, 2024

That is the mentioned issue and his solution; I can't understand what a current issue, can provide further details.

Recording.2024-10-15.160329.mp4

@SerJaimeLannister
Copy link
Author

instead of deno compile build/server/index.js , you have to try deno compile --no-check build/index.js for it to have web app also

also , even when you do that it shows an error on the first reload probably related to how deno runtime probably gets loaded into tmp for the first time

@SerJaimeLannister
Copy link
Author

Also a minor nitpick for which I am not sure deserves a full issue is currently we need to use https://github.com/pluvial/svelte-adapter-deno or something along this line & change svelte.config.js because the svelte-adapter-auto doesn't have a default runtime for deno , but this only adds friction I suppose , maybe with deno 2.0 , we can get automatic support for deno in sveltekit?

@yazan-abdalrahman
Copy link
Contributor

Sorry, I couldn't find any errors; maybe I misunderstood your requirements, but I believe you had an issue that was not caused by deno compile.

Recording.2024-10-15.161826.mp4

We should mention deno member; it will be more helpful in clarifying the situation.

@bartlomieju @dsherret

@mindon

This comment was marked as off-topic.

@opensas
Copy link

opensas commented Nov 23, 2024

I have the same issue as @yazan-abdalrahman

I do the build, but when I run deno run build/server/index.js nothing happens, and obviously after compiling it with deno run build/server/index.js I run ./server and nohting happens either

@dsherret
Copy link
Member

dsherret commented Nov 23, 2024

I haven't tested it, but there's a chance it might be fixed in canary (deno upgrade canary)

Edit: actually, looking at the reproduction probably not.

@opensas
Copy link

opensas commented Nov 23, 2024

ok, the problem was that we had to compile the build/index.js file instead of the build/server/index.js file

I also had to add a couple settings, like this:

$ deno compile --no-check --output server --allow-env --allow-net --unstable-node-globals build/index.js

$ ./server 
Listening on 0.0.0.0:3000

but when I browse the page I get a handler is not a function error:

$ curl -v localhost:3000
*   Trying 127.0.0.1:3000...
* Connected to localhost (127.0.0.1) port 3000 (#0)
> GET / HTTP/1.1
> Host: localhost:3000
> User-Agent: curl/7.81.0
> Accept: */*
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 500 Internal Server Error
< vary: Accept-Encoding
< transfer-encoding: chunked
< date: Sat, 23 Nov 2024 06:17:56 GMT
< 
* Connection #0 to host localhost left intact
handler is not a function

@opensas
Copy link

opensas commented Nov 23, 2024

Here I'll try to document every step taken to ease reproduction

$ deno run -A --reload npm:sv create sveltekit-deno-app

$ deno run -A --reload npm:sv create sveltekit-deno-app
┌  Welcome to the Svelte CLI! (v0.6.5)
│
◇  Which template would you like?
│  SvelteKit demo
│
◇  Add type checking with Typescript?
│  Yes, using Typescript syntax
│
◆  Project created
│
◇  What would you like to add to your project? (use arrow keys / space bar)
│  prettier, eslint
│
◇  Which package manager do you want to install dependencies with?
│  None

$ cd sveltekit-deno-app/

$ deno install --allow-scripts=npm:@sveltejs/[email protected]

$ deno run dev (works ok)

$ deno install npm:svelte-adapter-deno

update svelte.config.js

// import adapter from '@sveltejs/adapter-auto';
import adapter from 'svelte-adapter-deno';
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';

[...]
$ deno run build

$ deno compile --no-check --output server --allow-env --allow-net --unstable-node-globals build/index.js

$ ll -h server
-rwxr-xr-x 1 sas sas 174M Nov 23 15:51 server*

$ ./server 
Listening on http://0.0.0.0:3000

And I get this:

image

it seems like all the assets are not being found

image

If I run it like this:

$ deno run --allow-env --allow-read --allow-net build/index.js 
Listening on http://0.0.0.0:3000

it works ok

image

so it must be a problem with the compile command

@SerJaimeLannister
Copy link
Author

SerJaimeLannister commented Nov 23, 2024

Hmm very interesting , I tried to do what I had done earlier to get it to working and I also have gotten this same issue

image

My interest has been piqued once again. (I was so close to closing this issue)

It is showing this in the logs which made me realise that this might be the fault of the compiler and not the adapter https://github.com/pluvial/svelte-adapter-deno because I thought that the adapter hadn't been made compatible with the 5.0 release , but this error points to some compile issue

Error: Not found: /
at resolve2 (file:///tmp/deno-compile-binary/my-app/build/server/index.js:4194:18)
at resolve (file:///tmp/deno-compile-binary/my-app/build/server/index.js:4027:34)
at Object.handle (file:///tmp/deno-compile-binary/my-app/build/server/index.js:4262:71)
at respond (file:///tmp/deno-compile-binary/my-app/build/server/index.js:4025:43)
at eventLoopTick (ext:core/01_core.js:175:7) {
status: 404,
text: "Not Found"
}
Error: Not found: /favicon.png
at resolve2 (file:///tmp/deno-compile-binary/my-app/build/server/index.js:4194:18)
at resolve (file:///tmp/deno-compile-binary/my-app/build/server/index.js:4027:34)
at Object.handle (file:///tmp/deno-compile-binary/my-app/build/server/index.js:4262:71)
at respond (file:///tmp/deno-compile-binary/my-app/build/server/index.js:4025:43)
at eventLoopTick (ext:core/01_core.js:175:7) {
status: 404,
text: "Not Found"
}
(Edit: I had accidentally closed the issue , so sorry)

@SerJaimeLannister
Copy link
Author

Another thing to note is that deno doesn't work with the default database / authentication (lucia) example provided by sveltekit because sqllite node remapping isn't done or an error like this was shown , but I think it belongs in different issue

@Hugo-Dz
Copy link

Hugo-Dz commented Nov 27, 2024

Same issue here, unable to fetch assets / css files 404. I use the Node adapter since it works out of the box with Deno 2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly compile related to the `deno compile` feature
Projects
None yet
Development

No branches or pull requests

8 participants