nx icon indicating copy to clipboard operation
nx copied to clipboard

Warning shown about cjs format when NodeNext module used

Open Roaders opened this issue 6 months ago • 4 comments

Current Behavior

When building with @nx/js:tsc I get the following warning:

Package type is set to "module" but "cjs" format is included. Going to use "esm" format instead. You can change the package type to "commonjs" or remove type in the package.json file.

Despite me not setting format: "cjs" anywhere.

My module format is set to NodeNext in my tsconfig.json

Expected Behavior

When building an ESM package with module set to NodeNext this warning should not be shown

GitHub Repo

https://github.com/morganstanley/fdc3-web

Steps to Reproduce

Clone above repo

nx build fdc3-web

Nx Report

Node           : 22.13.1
OS             : win32-x64
Native Target  : x86_64-windows
npm            : 10.9.2

nx (global)    : 21.0.3
nx             : 21.0.3
@nx/js         : 21.0.3
@nx/jest       : 21.0.3
@nx/eslint     : 21.0.3
@nx/workspace  : 21.0.3
@nx/devkit     : 21.0.3
@nx/esbuild    : 21.0.3
@nx/node       : 21.0.3
@nx/vite       : 21.0.3
@nx/web        : 21.0.3
typescript     : 5.8.3
---------------------------------------
Registered Plugins:
@nx/eslint/plugin
@nx/vite/plugin
@nx/vite/plugin
---------------------------------------
Cache Usage: 726.05 KB / 47.69 GB

Failure Logs


Package Manager Version

No response

Operating System

  • [ ] macOS
  • [ ] Linux
  • [x] Windows
  • [ ] Other (Please specify)

Additional Information

the format that is used is not set in the options of the @nx/js:tsc executor (this caused quite a bit of confusion as when I tried to set it it had no effect). It is instead generated from the tsconfig file that is used. The format comes from the function determineModuleFormatFromTsConfig which only considers:

ts.ModuleKind.ES2015
ts.ModuleKind.ES2020
ts.ModuleKind.ES2022
ts.ModuleKind.ESNext

to be esm. NodeNext should be added

https://github.com/nrwl/nx/blob/43a20e2ecc104d072eb1071e24783890b6ecbcfe/packages/js/src/executors/tsc/tsc.impl.ts#L28

Roaders avatar May 21 '25 12:05 Roaders