Skip to content

feat: Support top-level await on Node 22.12+ #269

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

Merged
merged 3 commits into from
Jun 1, 2025

Conversation

epelc
Copy link
Contributor

@epelc epelc commented Dec 31, 2024

Fixes #268 which is broken on node v22.12.0 and later(works on <= v22.11.0). Gulp cli was trying to use require(), failing and not trying to fallback to import() since the error code changed. Previously gulp would detect the error and attempt to use import().

This makes it detect the new error code in node v22.12.0 and later. Keeps the old behavior to support older node versions as well.

See node change log which describes the changes that lead to this.

https://nodejs.org/en/blog/release/v22.12.0#requireesm-is-now-enabled-by-default

@epelc epelc changed the title Fix top level await not using import() Fix top level await requireOrImport not trying import() after failed require Dec 31, 2024
@mikestreety
Copy link

I can confirm this works for me and solves the problems I was having reported in this issue: #267

Is there anything stopping this being merged?

@phated
Copy link
Member

phated commented Jun 1, 2025

I need to figure out a regression test for this because CI isn't failing in #272 when it should be.

@phated
Copy link
Member

phated commented Jun 1, 2025

It looks like this will cause the failure:

const dynamicNoop = await Promise.resolve(function noop(cb) {
  cb();
});

export const registered = dynamicNoop;
export function exported(){};
export const string = 'no function';

@phated phated changed the title Fix top level await requireOrImport not trying import() after failed require feat: Support top-level await on Node 22.12+ Jun 1, 2025
epelc and others added 2 commits June 1, 2025 13:34
  - supports node v22.12.0 and later when using top level await
@phated phated force-pushed the top-level-await-imports branch from 174a192 to fd1742b Compare June 1, 2025 20:34
Copy link
Member

@phated phated left a comment

Choose a reason for hiding this comment

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

Excellent work here @epelc! Sorry for the delay but we'll get this released shortly.

@phated phated merged commit 902f5b2 into gulpjs:master Jun 1, 2025
26 checks passed
@epelc
Copy link
Contributor Author

epelc commented Jun 1, 2025

Excellent work here @epelc! Sorry for the delay but we'll get this released shortly.

Thanks! Excited to get this in. Been blocking a node upgrade.

Gulp works really well for auxiliary build steps around modern angular.

@mikestreety
Copy link

Thanks for getting this merged and released 🙏

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.

Node 22 ERR_REQUIRE_ASYNC_MODULE if gulpfile.mjs contains top-level await
3 participants