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

ReferenceError: Can't find variable: require_x #2858

Closed
Electroid opened this issue May 11, 2023 · 7 comments
Closed

ReferenceError: Can't find variable: require_x #2858

Electroid opened this issue May 11, 2023 · 7 comments
Labels
bug Something isn't working bundler Something to do with the bundler

Comments

@Electroid
Copy link
Contributor

It appears if an import is tree-shaked to not exist, the require_x() function is still included.

// @bun
// /Users/ashcon/Desktop/code/bun/test2/harness.ts
var {callerSourceOrigin } = import.meta.require("bun:jsc");

// test/parallel/test-arm-math-illegal-instruction.js
require_harness();
Object.getOwnPropertyNames(Math).forEach((functionName) => {
  if (!/[A-Z]/.test(functionName))
    Math[functionName](-0.5);
});

//# debugId=544DF241F070613BBBBBBBBBBBBBBBBB
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFs1NDRERjI0MUYwNzA2MTNCQkJCQkJCQkJCQkJCQkJCQiIsCiAgIm5hbWVzIjogW10KfQ==
@Electroid Electroid added bug Something isn't working bundler Something to do with the bundler labels May 11, 2023
@Jarred-Sumner
Copy link
Collaborator

is this still happening?

@pcfreak30
Copy link

pcfreak30 commented Aug 24, 2023

I think mine is similar.

#!/usr/bin/env node
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
var __require = (id) => {
  return import.meta.require(id);
};


// package.json
var require_package = __commonJS((exports, module) => {

i have a case with loader: require

if i hack and replace that with __require still crashes.

also tried loader: Function("return __require;")()

seems to get stuck on its own generated code?

per @Jarred-Sumner Yes the import.meta.require thing is a bug that needs to be fixed.

This is still a bug since at-least 0.7.x.

@pcfreak30
Copy link

Still a bug as of 0.8.1.

Also, if i set package.json type to module, i get TypeError: (intermediate value).require is not a function instead on running the bundled file.

@venkatd
Copy link

venkatd commented Sep 7, 2023

I'm having the same issue as @pcfreak30 also on 0.8.1

@rupurt
Copy link
Contributor

rupurt commented Nov 11, 2023

I also get this in bun v1.0.11 when --target bun but only in a compiled executable. Using bun run ... works fine

@Electroid
Copy link
Contributor Author

This was fixed in a recent release of Bun.

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

6 participants