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

Error when lighthouse is bundled with --compile option #17969

Open
mageekguy opened this issue Mar 7, 2025 · 0 comments
Open

Error when lighthouse is bundled with --compile option #17969

mageekguy opened this issue Mar 7, 2025 · 0 comments
Labels
bug Something isn't working needs triage

Comments

@mageekguy
Copy link

mageekguy commented Mar 7, 2025

What version of Bun is running?

1.2.5-canary.78+94ab3007a

What platform is your computer?

OSX on M3

What steps can reproduce the bug?

I would like to create an executable from my app using --compile option.
My app has https://www.npmjs.com/package/lighthouse as dependency.
The compilation process works fine, but at runtime, I have several errors related to .json files not found in the binary.
It seems that at compile time, bun transliterate .json files to .js file, according to its documentation.
However, locale management system of lighthouse try to read and parse some .json files (ar.json and so on), so they are unavailable in the binary, because they has been transliterated to .js file.
I have tried several workaround without any success, sadly (for example --loader .json:file, copy .json files before compilation process in the app's root directory and include them as assets…).
It seems that there is also the same kind of problem with .html file used as template by lighthouse.
Obviously, all is fine when I'm using -e lighthouse at compile time, but I don't want having lighthouse as external package.
Do you have a solution?

mageekguy@fedora:~/Tmp
4|1004> bun init

✓ Select a project template: Blank

 + .gitignore
 + package.json
 + index.ts
 + tsconfig.json (for editor autocomplete)
 + README.md

To get started, run:

    bun run index.ts

bun install v1.2.5-canary.78 (94ab3007)

+ [email protected]
+ @types/[email protected]

6 packages installed [791.00ms]

mageekguy@fedora:~/Tmp
5|1005> bun install lighthouse
bun add v1.2.5-canary.78 (94ab3007)

installed [email protected] with binaries:
 - lighthouse
 - smokehouse
 - chrome-debug

140 packages installed [1320.00ms]
mageekguy@fedora:~/Tmp
6|1006> vi app.js
mageekguy@fedora:~/Tmp
7|1007> bun build ./app.js --compile --outfile=./compiled_app
  [62ms]  bundle  1611 modules
  [73ms] compile  ./compiled_app
mageekguy@fedora:~/Tmp
8|1008> ./compiled_app 
69364 | }
69365 | 
69366 | // node_modules/lighthouse/shared/localization/locales.js
69367 | import fs from "fs";
69368 | var moduleDir = getModuleDirectory(import.meta);
69369 |   ar: JSON.parse(fs.readFileSync(`${moduleDir}/locales/ar.json`, "utf8")),
                                        ^
ENOENT: no such file or directory, open '/$bunfs/root/locales/ar.json'
    path: "/$bunfs/root/locales/ar.json",
 syscall: "open",
   errno: -2,
    code: "ENOENT"

      at /$bunfs/root/compiled_app:69369:33

Bun v1.2.5-canary.78+94ab3007a (Linux arm64)

app.js contents is:

import lighthouse from "lighthouse"

console.log('Hello, lighthouse!')

What is the expected behavior?

'Hello, lighthouse!'

What do you see instead?

69364 | }
69365 |
69366 | // node_modules/lighthouse/shared/localization/locales.js
69367 | import fs from "fs";
69368 | var moduleDir = getModuleDirectory(import.meta);
69369 | ar: JSON.parse(fs.readFileSync(${moduleDir}/locales/ar.json, "utf8")),
^
ENOENT: no such file or directory, open '/$bunfs/root/locales/ar.json'
path: "/$bunfs/root/locales/ar.json",
syscall: "open",
errno: -2,
code: "ENOENT"

  at /$bunfs/root/compiled_app:69369:33

Bun v1.2.5-canary.78+94ab3007a (Linux arm64)

@mageekguy mageekguy added bug Something isn't working needs triage labels Mar 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage
Projects
None yet
Development

No branches or pull requests

1 participant