Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@JoshuaCWebDeveloper
Copy link
Contributor

Current Behavior

A tsconfig module value of nodenext is treated as a CJS format, which produces a warning when built due to it being used in ESM projects.

Expected Behavior

A tsconfig module value of nodenext is now teated as an ESM format, producing no warning when built.

Related Issue(s)

Fixes #31295

@vercel
Copy link

vercel bot commented Aug 12, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Updated (UTC)
nx-dev Ready Ready Preview Aug 29, 2025 3:44am

@nx-cloud
Copy link
Contributor

nx-cloud bot commented Aug 12, 2025

🤖 Nx Cloud AI has analyzed the error but could not create a fix

No fix generated, but analysis is available • View Fix ↗


View your CI Pipeline Execution ↗ for commit 3b64359

Command Status Duration Result
nx affected --targets=lint,test,build,e2e,e2e-c... ❌ Failed 40m 18s View ↗
nx run-many -t check-imports check-commit check... ✅ Succeeded 1m 56s View ↗
nx-cloud record -- nx-cloud conformance:check ✅ Succeeded 2s View ↗
nx-cloud record -- nx format:check ✅ Succeeded 6s View ↗
nx-cloud record -- nx sync:check ✅ Succeeded 5s View ↗
nx documentation ✅ Succeeded 3m View ↗

☁️ Nx Cloud last updated this comment at 2025-08-14 03:07:42 UTC

@JoshuaCWebDeveloper
Copy link
Contributor Author

JoshuaCWebDeveloper commented Aug 12, 2025

Failed check is due to failing test in angular:test on master, unclear whether or not the fix is to just update the snapshot.

@Coly010
Copy link
Contributor

Coly010 commented Aug 18, 2025

Hey @JoshuaCWebDeveloper I'm not sure if this is 100% correct.

NodeNext will be ESM if the nearest package.json type is module, and/or depending on the file extension of files.

@JoshuaCWebDeveloper
Copy link
Contributor Author

Hey @JoshuaCWebDeveloper I'm not sure if this is 100% correct.

NodeNext will be ESM if the nearest package.json type is module, and/or depending on the file extension of files.

@Coly010 Good point. Looked at this a bit closer, format is an optional option to updatePackageJson() because it is already checking the package.json type. getUpdatedPackageJsonContent() also has logic for handling no given format.

My new solution passes a format of undefined to updatePackageJson() for the node* module types. This allows updatePackageJson() to determine the correct format (currently checks package.json, and can check file extensions in the future if it needs to). I also check every single tsconfig module option for completeness and to make it super clear what the method returns now that I'm introducing a third return type.

Copy link
Member

@leosvelperez leosvelperez left a comment

Choose a reason for hiding this comment

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

Thanks for contributing! Apologies for the delay.

Please rebase the changes and update the call sites (tsc.impl.ts and tsc.batch-impl.ts) to handle the undefined result and avoid providing [undefined] to the updatePackageJson function. Usages should be something like:

const format = determineModuleFormatFromTsConfig(options.tsConfig);
updatePackageJson(
  {
    ...options,
    additionalEntryPoints: createEntryPoints(
      options.additionalEntryPoints,
      context.root
    ),
    format: format ? [format] : undefined,
  },
  context,
  target,
  dependencies
);

case ts.ModuleKind.Preserve:
return 'cjs';
case ts.ModuleKind.Node16:
case ts.ModuleKind.Node18:
Copy link
Member

Choose a reason for hiding this comment

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

Please add Node20.

@Coly010
Copy link
Contributor

Coly010 commented Dec 11, 2025

Should be handled now by: #31508

@Coly010 Coly010 closed this Dec 11, 2025
@github-actions
Copy link
Contributor

This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 17, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Warning shown about cjs format when NodeNext module used

3 participants