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

@nx/js doesn't work properly on TS configs that extend ESM-based configs #28492

Closed
1 of 4 tasks
porteneuve opened this issue Oct 17, 2024 · 1 comment
Closed
1 of 4 tasks

Comments

@porteneuve
Copy link

Current Behavior

We're using Nx release management over a TS project, which requires @nx/js. Our TS config files are based off various presets, either well-known community resources like @tsconfig/recommended or our own in-house presets. The latter are ESM packages that use exports fields in their package.json to expose /tsconfig.json over a file not located at package root.

Unfortunately, @nx/js relies on ts-node for parsing TS configs, with a fixed version of 10.9.1, when 10.9.2 was published over 10 months ago, allowing for proper import conditions handling, which fixes this issue.

So attempting to run nx release on such a project right now yields very confusing errors, as this happens deeply nested in your code when trying to set up the changelog generator, and any error in that scope is surfaced as "couldn't resolve the generator," when the file is actually right there.

(Generally, ts-node is basically abandonware at this point and it would be advisable for Nx JS-related projects to switch to other options for handling TS code, even more so for handling JS code.)

Expected Behavior

Generally, Nx should be able to process any TS Config that tsc itself can process, and should be able to work over any ESM module that uses conditional exports / imports.

In this particular case, it shouldn't fail to resolve the changelog generator just because the scope's TS config extends from a file that is exposed through a module's ESM exports field.

This can easily be achieve by bumping your ts-node dependency within the packages/js/package.json file to 10.9.2. I'm going to send a PR that does just that.

Note to readers: in the meantime, you can get this on your existing codebase by adding an npm override to your root package.json:

"overrides": {
  "@nx/js": {
    "ts-node": "10.9.2"
  }
}

GitHub Repo

https://github.com/tdd/nx-js-issue-demo

Steps to Reproduce

git clone https://github.com/tdd/nx-js-issue-demo.git
cd nx-js-issue-demo
npm install
npx nx release --first-release --dry-run

Nx Report

NX Report complete - copy this into the issue template

Node : 20.11.1
OS : darwin-arm64
Native Target : aarch64-macos
npm : 10.2.4

nx : 20.0.0
@nx/js : 20.0.0
@nx/workspace : 20.0.0
@nx/devkit : 20.0.0
typescript : 5.6.3

Failure Logs

Convert compiler options from json failed, File '@nx-demo/tsconfig/exported-config.json' not found.

NX There was an error when resolving the configured changelog renderer at path: node_modules/nx/release/changelog-renderer

The relevant config is defined here: nx.json, lines 5-10

NX Cannot read properties of undefined (reading 'map')

Pass --verbose to see the stacktrace.

NOTE: The "dryRun" flag means no changes were made.

Package Manager Version

No response

Operating System

  • macOS
  • Linux
  • Windows
  • Other (Please specify)

Additional Information

No response

@tdd
Copy link

tdd commented Oct 17, 2024

OK, after further investigation in the minimum reproducible repo I provided, it sounds like the issue in my original project came more from older version of @swc/core and @swc-node/register, which upgrading to ts-node 10.9.2 fixed, but on a fresh install with latest versions of the SWC packages, using ts-node 10.9.2 actually breaks, when 10.9.1 has it all working.

I would advise to close the issue then :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants