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

--compile TypeError: Argument must be a file URL on a new Sveltekit #5178

Closed
kevincobain2000 opened this issue Sep 13, 2023 · 13 comments · Fixed by #8023
Closed

--compile TypeError: Argument must be a file URL on a new Sveltekit #5178

kevincobain2000 opened this issue Sep 13, 2023 · 13 comments · Fixed by #8023
Labels
bug Something isn't working bundler Something to do with the bundler

Comments

@kevincobain2000
Copy link

kevincobain2000 commented Sep 13, 2023

What version of Bun is running?

1.0.1

What platform is your computer?

Darwin 21.6.0 arm64 arm, Mac M1

What steps can reproduce the bug?

Steps to reproduce

Same steps as: https://bun.sh/guides/ecosystem/sveltekit

npm create svelte@latest my-app
cd my-app
bun install
bun add svelte-adapter-bun

# update adapter to: import adapter from 'svelte-adapter-bun'
vi svelte.config.js

bun run build
bun build build/index.js --compile --outfile binary
./binary

Error

╰─$ ./binary
17771 |   const protocol = protocol_header && headers.get(protocol_header) || "http";
17772 |   const host = headers.get(host_header);
17773 |   return `${protocol}://${host}`;
17774 | };
17775 |
17776 | var __dirname2 = path.dirname(fileURLToPath(new URL(import.meta.url)));
                                 ^
TypeError: Argument must be a file URL
      at compiled://root/binary:17776:30

Notes

Every step of build passes as ok, bun run dev and bun build/index.js work fine.
Just that the compiled bun binary cannot start the Sveltekit app and throws the error above.

What is the expected behavior?

Should start server on localhost:3000

What do you see instead?

No response

Additional information

Same issues - previously closed

#1069
#1070

Other similar issues

#4592

@kevincobain2000 kevincobain2000 added the bug Something isn't working label Sep 13, 2023
@AndreiLucaci
Copy link

AndreiLucaci commented Sep 13, 2023

The bug still reproduces...

command

bun build . --compile --outfile out

error when running

2060 | // node_modules/clipboardy/lib/linux.js
2061 | var import_execa2 = __toESM(require_execa(), 1);
2062 | import path from "path";
2063 | import {fileURLToPath} from "url";
2064 |
2065 | var __dirname2 = path.dirname(fileURLToPath(import.meta.url));
                                 ^
TypeError: Argument must be a file URL
      at compiled://root/auth:2065:30
      at processTicksAndRejections (:1:2602)

and the original source code

const profilePath = `${import.meta.dir}/profiles/${stage}.json`;

const profileFile = Bun.file(profilePath);

@Jarred-Sumner
Copy link
Collaborator

Oh interesting that makes sense

We need to make fileURL allow compiled:// and pretend it’s the same as file://

@kevincobain2000
Copy link
Author

It’d be a killer feature if compiled binaries work like butter. All in all, bun is really performant for http requests, I didn’t expect that.

@kevincobain2000
Copy link
Author

Hi @Jarred-Sumner
Sorry, are there any updates on this. Really looking forward to this feature working.

@robert-boulanger
Copy link

Still reproducable in 1.06
Are there any plans when this will be fixed ? I don't want to be nasty, just want to plan myself

@Electroid Electroid added the bundler Something to do with the bundler label Oct 27, 2023
@faburem
Copy link

faburem commented Oct 30, 2023

I agree, it would be a killer feature if this would "just work".

@kevincobain2000
Copy link
Author

Update: Occurs still on bun 1.0.21

@Jarred-Sumner
Copy link
Collaborator

Oh I see why this is happening.

@kevincobain2000
Copy link
Author

Waiting eagerly! Thanks @Jarred-Sumner

@robert-boulanger
Copy link

@kevincobain2000 Not just you, I'm waiting as well

Jarred-Sumner added a commit that referenced this issue Jan 7, 2024
Jarred-Sumner added a commit that referenced this issue Jan 7, 2024
* Fixes #5178

* Update comment

---------

Co-authored-by: Jarred Sumner <[email protected]>
@Jarred-Sumner
Copy link
Collaborator

This will ship in Bun v1.0.22.

If you run bun upgrade --canary later tonight, you can try it early

@kevincobain2000
Copy link
Author

kevincobain2000 commented Jan 7, 2024

Thanks.
It builds well! On --canary but gives follow new error now.
It does start the server though in both cases.

╰─$ bun upgrade --canary                                                                                                                                                                                                                                               
Congrats! You're already on the latest canary build of Bun

To downgrade to the latest stable release, run bun upgrade --stable
╭─pulkit.@JP- ~/git/my-app
╰─$ date
Sun Jan  7 14:32:33 JST 2024

Reproduce steps

Create new SvelteKit app

npm create svelte@latest my-app
cd my-app
bun install
bun add svelte-adapter-bun

# update adapter to: import adapter from 'svelte-adapter-bun'
vi svelte.config.js

bun run build
bun build build/index.js --compile --outfile binary
./binary

Error 1) from brand new sveltekit project

╰─$ HOST=localhost PORT=3005 ./binary
Listening on localhost:3005
17904 |     }
17905 |   });
17906 | };
17907 | var get_origin = function(headers2) {
17908 |   const protocol = protocol_header && headers2.get(protocol_header) || "https";
17909 |   const host = headers2.get(host_header);
                       ^
TypeError: Invalid header name: ''
      at get_origin (/$bunfs/root/binary:17909:16)
      at ssr7 (/$bunfs/root/binary:17877:25)

17904 |     }
17905 |   });
17906 | };
17907 | var get_origin = function(headers2) {
17908 |   const protocol = protocol_header && headers2.get(protocol_header) || "https";
17909 |   const host = headers2.get(host_header);

Extra Info below:

Error 2) From a different project. It is unable to find the assets

1/7/2024, 2:50:23 PM GET /_app/immutable/nodes/3.2ddf9d5c.js (2ms) 127.0.0.1 404
7873 |           event: event2,
7874 |           options: options2,
7875 |           manifest,
7876 |           state,
7877 |           status: 404,
7878 |           error: new Error(`Not found: ${event2.url.pathname}`),
                        ^
error: Not found: /_app/immutable/assets/0.fb1cca37.css
      at /$bunfs/root/binary:7878:18
      at resolve (/$bunfs/root/binary:7793:28)
      at resolve (/$bunfs/root/binary:7740:49)
      at /$bunfs/root/binary:333:28
      at logger (/$bunfs/root/binary:331:21)
      at /$bunfs/root/binary:7738:28
      at processTicksAndRejections (:61:77)

1/7/2024, 2:50:23 PM GET /_app/immutable/assets/0.fb1cca37.css (1ms) 127.0.0.1 404
1/7/2024, 2:50:25 PM GET /api/repo (4ms) 127.0.0.1 200
1/7/2024, 2:50:25 PM GET /~partytown/partytown-sw.js (6ms) 127.0.0.1 200
^C
╭─pulkit.@JP-^M ~/git/my-app2/build ‹master●›
╰─$ find .|grep 3.2ddf9d5c.js                                                                                                                                                                                                                                           130 ↵
./client/_app/immutable/nodes/3.2ddf9d5c.js.br
./client/_app/immutable/nodes/3.2ddf9d5c.js.gz
./client/_app/immutable/nodes/3.2ddf9d5c.js 

And it has #1425 issue too.
The ConnectionRefused doesn't show on bun run dev, but on bun run build; bun run build/index.js

@janek
Copy link

janek commented Jan 7, 2024

I had a similar issue, also happening only on compilation, but with Prettier and not SvelteKit. bun upgrade --canary solved it for me (I was on 1.0.21 before).

Reproduction, in case it helps:

import * as prettier from "prettier";
const html = await prettier.format("<h1>Formatted successfully</h1>", { parser: "html" });
console.log(html)

For this code, bun run file.ts would work as expected. But bun build file.ts and then ./file would give me the following error:

96641 | async function clearCache4() {
96642 |   clearCache2();
96643 |   clearCache3();
96644 | }
96645 | var require2 = __prettierCreateRequire(import.meta.url);
96646 | var __filename2 = __prettierFileUrlToPath(import.meta.url);
                                              ^
TypeError: Argument must be a file URL
      at compiled://root/test:96646:19
      at processTicksAndRejections (:61:77)

Guess I'm pretty lucky this got fixed a few hours before I stumbled upon it ^^
Thank you for your work!

ryoppippi pushed a commit to ryoppippi/bun that referenced this issue Feb 1, 2024
* Fixes oven-sh#5178

* Update comment

---------

Co-authored-by: Jarred Sumner <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working bundler Something to do with the bundler
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants