Skip to content

Conversation

nirinchev
Copy link
Collaborator

Description

Starting with node 23, support for require-ing ES modules no longer throws but instead prints a warning in the output. This is problematic for homebrew users since homebrew aggressively upgrades node, regardless of what the preferred node version is for a package. This PR takes one approach, which is to suppress experimental warnings altogether for Node 23. This is only manually tested since I'm not convinced it's the approach we'd like to take (see Open Questions) - once we've settled on it, I'll need to figure out a way to test.

Open Questions

This feels a bit hacky and I'm not convinced this is the long term fix we'd like to use. Here are a few alternatives, ranked from easy to hard:

  1. We could try and more narrowly suppress the specific require() warning.
  2. We could restore the original warning emitter after importing fetch.
  3. We could change moduleResolution to NodeNext and fix the issues that this causes (unfortunately, I wan't able to trace what they were).
  4. We could migrate to ES modules.

Checklist

@nirinchev nirinchev requested a review from addaleax November 11, 2024 16:08

warningsSuppressed = true;
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is the approach we're going with – which I think is pretty reasonable – then I'd do that in the mongosh CLI itself, like we already disable warnings for the case of the compiled executable in packages/cli-repl/src/run.ts, because that's where we're expecting overrides for Node.js behavior and other modifications to truly global state, how does that sound to you?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, that sounds reasonable to me! I guess originally I wanted to put it next to the code that does the requiring shenanigans, but you're right that the warnings being displayed or not is better left to the user-facing application.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think there's also just going to be more code running into this problem in the future, the more popular ESM gets in our dependencies, not just the code here

@nirinchev
Copy link
Collaborator Author

Closing in favor of mongodb-js/mongosh#2258.

@nirinchev nirinchev closed this Nov 12, 2024
@nirinchev nirinchev deleted the ni/node-23 branch November 12, 2024 09:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants