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

can't find variable: module #4818

Closed
sibelius opened this issue Sep 10, 2023 · 5 comments · Fixed by #5889
Closed

can't find variable: module #4818

sibelius opened this issue Sep 10, 2023 · 5 comments · Fixed by #5889
Labels
bug Something isn't working

Comments

@sibelius
Copy link

What version of Bun is running?

1.0.0+822a00c4d508b54f650933a73ca5f4a3af9a7983

What platform is your computer?

Darwin 22.5.0 arm64 arm

What steps can reproduce the bug?

if (!isMainScript(module) {
    return;
  }
export const isMainScript = (module) => {
  if (!module.parent) {
    return true;
  }

  return false;
};

module resolves to NodeModule inside @types/node/globals.d.ts

declare var module: NodeModule;

What is the expected behavior?

it should work

What do you see instead?

ReferenceError: Can't find variable: module

Additional information

No response

@sibelius sibelius added the bug Something isn't working label Sep 10, 2023
@matheusinfo
Copy link

matheusinfo commented Sep 10, 2023

I tried to reproduce it here, but apparently it works:

FILE: index.ts

const { isMainScript } = require("./main-script");

if (!isMainScript(module)) {
    console.log("Not main script");
}
FILE: main-script.ts

export const isMainScript = (module) => {
    if (!module.parent) {
        return true;
    }

    return false;
};

The point is that my module resolves from bun-types/types.d.ts. Do you have any repository with this code?

@jld-adriano
Copy link

I made a repro https://github.com/jld-adriano/bun-repro-4818
Just bun index.ts

I think it's related to a module that imports another module that is in "module mode" because it imports from another one. I had to do 3 files to repro but maybe there's another way

@jld-adriano
Copy link

jld-adriano commented Oct 26, 2023

@paperdave my repro still errors out, with the same error

Tested on 1.0.7

@vindard
Copy link

vindard commented Nov 20, 2023

I made a repro https://github.com/jld-adriano/bun-repro-4818 Just bun index.ts

I think it's related to a module that imports another module that is in "module mode" because it imports from another one. I had to do 3 files to repro but maybe there's another way

Bump

vindard added a commit to GaloyMoney/blink that referenced this issue Nov 20, 2023
This was removed to support using bun as a runner.
(see oven-sh/bun#4818 (comment))

There are other issues with bun as well for now, so I'm reverting this
until we need to use bun as a runner and the issue is still not fixed in
bun.
vindard added a commit to GaloyMoney/blink that referenced this issue Nov 21, 2023
This was removed to support using bun as a runner.
(see oven-sh/bun#4818 (comment))

There are other issues with bun as well for now, so I'm reverting this
until we need to use bun as a runner and the issue is still not fixed in
bun.
vindard added a commit to GaloyMoney/blink that referenced this issue Nov 21, 2023
This was removed to support using bun as a runner.
(see oven-sh/bun#4818 (comment))

There are other issues with bun as well for now, so I'm reverting this
until we need to use bun as a runner and the issue is still not fixed in
bun.
bodymindarts pushed a commit to GaloyMoney/blink that referenced this issue Nov 21, 2023
* fix(api): remove admin server start from public server module

With the removal of the 'require.main' check, the admin server gets
started once on import and then again in the explicit admin server call
in graphql-main-server.ts. This is to remove the 2nd call from
main-server.

* fix(api): re-add 'require.main' check & admin call from main server

This was removed to support using bun as a runner.
(see oven-sh/bun#4818 (comment))

There are other issues with bun as well for now, so I'm reverting this
until we need to use bun as a runner and the issue is still not fixed in
bun.

* chore(api): swap ts-node for tsx

* chore(api): add package.json scripts for dev servers

* build: add dev-public & dev-admin commands to BUCK

* build: add dev option for til api run

* build: add local file srcs to dev-api rule

* chore(api): remove admin server redundant run code

* refactor(api): separate public/admin/run api code

* chore: switch tsx in bats test helper

* chore: switch tsx in top-level bats test helper
@paperdave
Copy link
Collaborator

module and import/export cant be used in the same file. @Jarred-Sumner

image

it seems the work done in #7223 to display a better error message here does not work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants