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

[Bug]: require.main has invalid value null #15185

Closed
jlherren opened this issue Jul 14, 2024 · 6 comments
Closed

[Bug]: require.main has invalid value null #15185

jlherren opened this issue Jul 14, 2024 · 6 comments

Comments

@jlherren
Copy link

Version

29.7.0

Steps to reproduce

git clone https://github.com/jlherren/jest-test
cd jest-test
npm install
node bin/app.js
npm run test

Expected behavior

When running node bin/app.js, it prints "Note that require.main is undefined".

Actual behavior

During npm run test, it prints "Note that require.main is null".

Additional context

According to the nodejs docs, require.main is a reference to the entry module, when the entry script is CJS and undefined otherwise. The value null is not valid for require.main. This confuses some third-party libraries that check for CJS vs ESM with typeof require.main === 'object', (since typeof null is "object"). One such example is umzug, when it loads migration files.

Environment

System:
    OS: Linux 6.1 Debian GNU/Linux 12 (bookworm) 12 (bookworm)
    CPU: (12) x64 Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz
  Binaries:
    Node: 18.20.4 - /usr/bin/node
    Yarn: 1.22.22 - /usr/bin/yarn
    npm: 10.7.0 - /usr/bin/npm
    pnpm: 8.6.5 - /usr/bin/pnpm
  npmPackages:
    jest: ^29.7.0 => 29.7.0
Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.

@github-actions github-actions bot added the Stale label Aug 13, 2024
@jlherren
Copy link
Author

This is still happening, including in 30.0.0-alpha.6, although for some reason the console.log message isn't visible anymore. I have updated the test to actually make an assertion.

@github-actions github-actions bot removed the Stale label Aug 13, 2024
Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.

@github-actions github-actions bot added the Stale label Sep 12, 2024
Copy link

This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.

1 similar comment
Copy link

This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Oct 12, 2024
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant