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

[Node.js 23.x] CJS module gulp-cli\lib\shared\require-or-import.js is loading ESM gulpfile.js using require() #267

Closed
4 tasks done
cedx opened this issue Oct 29, 2024 · 6 comments

Comments

@cedx
Copy link

cedx commented Oct 29, 2024

Before you open this issue, please complete the following tasks:

  • use the search bar at the top of the page to search this repository for similar issues or discussions that have already been opened.
  • if you are looking for help from the gulp team or community, open a discussion.
  • if you think there is a problem with the plugin you're using, open a discussion.
  • if you think there is a bug in our code, open this issue.

What were you expecting to happen?

Launching a Gulp task doesn't produce any warning.

What actually happened?

Since Node.js v23, an ExperimentalWarning is triggered.

This is because the requireOrImport() function uses require() to check if the gulpfile is a CommonJS module... but now Node.js allows to use require() for loading ES modules. So the ERR_REQUIRE_ESM error is not triggered anymore.

See: https://nodejs.org/en/blog/release/v23.0.0

Please give us a sample of your gulpfile

This issue is not related to the content of the gulpfile.
But feel free to test this project: https://github.com/cedx/lcov.js

Terminal output / screenshots

(node:26792) ExperimentalWarning: CommonJS module [...]\gulp-cli\lib\shared\require-or-import.js is loading ES Module [...]\gulpfile.js using require().

Please provide the following information:

  • OS & version [e.g. MacOS Catalina 10.15.4]: Windows 11
  • node version (run node -v): 23.1.0
  • npm version (run npm -v): 10.9.0
  • gulp version (run gulp -v): CLI version: 3.0.0, Local version: 5.0.0

Additional information

The launched tasks still run fine (unless the gulpfile uses top-level await). There is no runtime error, just an ExperimentalWarning.

@jtrumbull
Copy link

Same issue, same environment

@mikestreety
Copy link

I have just been experiencing this same issue on MacOS (And in Docker Alpine) with Node 22.12 - We've had to fix to 22.11 to resolve.

@ehmicky
Copy link

ehmicky commented Dec 10, 2024

Node.js 23.4.0 does not print this type of warnings anymore, so this issue should now be solved.

See also debug-js/debug#975 which had a similar problem.

@cedx
Copy link
Author

cedx commented Dec 12, 2024

I confirm : with Node 23.4.0, the warning is not displayed anymore.
nodejs/node#55960

@cedx cedx closed this as completed Dec 12, 2024
@mikestreety
Copy link

mikestreety commented Dec 12, 2024

Hey,

I get that this is fixed for those running 23.4, however 23 isn't on LTS and isn't the default Node version downloaded when navigating to https://nodejs.org/en/download/package-manager.

22.12 is also the Node version used when using any of the lts Docker images, which I can imagine a lot of businesses (like ours) do.

Sorry! I may be misunderstanding the linked issue so it may be also resolved in 22.12 too.

Thanks. We appreciate everything you do 🙏

@cedx
Copy link
Author

cedx commented Jan 2, 2025

@mikestreety It should also be fixed in version 22.12.
nodejs/node#56040

it will emit an experimental warning unless require() comes from a path that contains node_modules

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

No branches or pull requests

4 participants