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

bun build --compile error: Cannot find module "./engines/boa.js" from "/$bunfs/root/esvu" #13672

Open
guest271314 opened this issue Sep 1, 2024 · 2 comments
Labels
bug Something isn't working bundler Something to do with the bundler

Comments

@guest271314
Copy link
Contributor

What version of Bun is running?

1.1.26

What platform is your computer?

5.15.0-43-generic x86_64 x86_64 x86_64 GNU/Linux

What steps can reproduce the bug?

$ bun install esvu
$ bun build ./node_modules/esvu/src/bin.js --compile --packages=bundle --root=./node_modules/esvu/src/ --outfile=esvu
$ esvu --help

What is the expected behavior?

The compiled esvu executable to print the help entries.

What do you see instead?

$ ./esvu --help
error: Cannot find module "./engines/boa.js" from "/$bunfs/root/esvu"

Bun v1.1.26 (Linux x64 baseline)

Additional information

Deno's compile just works.

$ deno compile -A npm:esvu
$ ./esvu --help
esvu [command]

Commands:
  esvu install <engine>    Install <engine>
  esvu uninstall <engine>  Uninstall <engine>
  esvu update <engine>     Update <engine>

Options:
  --help     Show help                                                 [boolean]
  --version  Show version number                                       [boolean]
  --engines
  --fast

@guest271314 guest271314 added bug Something isn't working needs triage labels Sep 1, 2024
@guest271314
Copy link
Contributor Author

The issue is /node_modules/esvu/dist/src/index.js

'use strict';

const fs = require('fs');
const path = require('path');

const engines = {};
const enginesByName = {};
fs.readdirSync(path.join(__dirname, 'engines'))
  .forEach((f) => {
    if (!f.endsWith('.js')) {
      return;
    }
    const e = require(`./engines/${f}`);
    engines[e.config.id] = e;
    enginesByName[e.config.name.toLowerCase()] = e;
  });

becomes

// node_modules/esvu/src/index.js
var require_src2 = __commonJS((exports, module) => {
  function getInstaller(name) {
    name = name.toLowerCase();
    if (engines[name]) {
      return engines[name];
    }
    if (enginesByName[name]) {
      return enginesByName[name];
    }
    return;
  }
  var __dirname = "/home/user/node_modules/esvu/src";
  var fs = import.meta.require("fs");
  var path = import.meta.require("path");
  var engines = {};
  var enginesByName = {};
  fs.readdirSync(path.join(__dirname, "engines")).forEach((f) => {
    if (!f.endsWith(".js")) {
      return;
    }
    const e = import.meta.require(`./engines/${f}`);
    engines[e.config.id] = e;
    enginesByName[e.config.name.toLowerCase()] = e;
  });
  exports.getInstaller = getInstaller;
  exports.engines = engines;
});

The bundle is looking for ./engines/${f} in the current directory. The path should be ${__dirname}/engines/${f}.

Adding the __dirname manually to the bundle works.

@nektro nektro added bundler Something to do with the bundler and removed needs triage labels Oct 12, 2024
@guest271314
Copy link
Contributor Author

Looks like the larger issue is the result of bun build --compile still depends on the source files after executable compilation #14676.

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

No branches or pull requests

2 participants