Git Product home page Git Product logo

Comments (5)

rvanderfeer avatar rvanderfeer commented on June 7, 2024 4

I ran into this error too, the BullMQ method that @Curetix mentions seems to hold a clue; the method's comment references a discussion on stack overflow which states;

Node publishes all the module search paths to module.paths. We can traverse these and pick the first one that resolves.

It would appear that Bun follows this behavior only when running.
When building/compiling the 'module' global seems to be replaced somehow, which suggests to me it may not be recognized or set as a global.

A simple test file confirms this;

// index.ts
console.log(module.paths);

When launched with bun run this will produce an array output.
When built via bun build --target bun --outfile out.js index.ts and subsequently run via bun run out.js this produces undefined.

@knajjars I suggest you change the title of your bug report so to something like module.paths not set when using bun build - surely there will be modules other than BullMQ suffering from this bug.

EDIT: There seems to be a bit more to it; apparently this is caused by BullMQ using the module.paths to dynamically load Lua files onto the Redis instance, which would hide these files from the Bun bundler. These would need to be turned into assets by the bundler somehow.

from bun.

Curetix avatar Curetix commented on June 7, 2024 3

I'm getting the same error from a bundled BullMQ server script. Running the TS file directly works fine, but building (with target bun) and then running it throws ReferenceError: Can't find variable: module_script_loader.

Seems to be caused by this function, which gets bundled to this:

var getPkgJsonDir = function() {
  for (const modPath of module_script_loader.paths || []) {
    try {
      const prospectivePkgJsonDir = path3.dirname(modPath);
      fs2.accessSync(modPath, fs2.constants.F_OK);
      return prospectivePkgJsonDir;
    } catch (e) {
    }
  }
  return "";
};

from bun.

codaxiom avatar codaxiom commented on June 7, 2024 2

Any news on this ?

from bun.

mrsum avatar mrsum commented on June 7, 2024 1

Same error

from bun.

MaikuMori avatar MaikuMori commented on June 7, 2024

Using --compile I get:

ReferenceError: Can't find variable: module_script_loader
      at getPkgJsonDir (/$bunfs/root/cli:46442:25)
      at new ScriptLoader (/$bunfs/root/cli:46509:21)
      at /$bunfs/root/cli:46722:20

from bun.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.