nx icon indicating copy to clipboard operation
nx copied to clipboard

Bug: @nrwl/js:tsc Invalid extends in tmp tsConfig - path.relative not being aware of current working dir

Open alexandrebodin opened this issue 2 years ago • 2 comments

Current Behavior

When running the tsc executor to build a package, if I run the command from the root directory of the monorepo or the pacakge itself one (root) will work just fine while the other will not transpile anyfile.

I pinpointed the issue here https://github.com/nrwl/nx/blob/master/packages/workspace/src/utilities/buildable-libs-utils.ts#L161.

where path.relative should make sure that tsConfigPath is an absolute so it is valid weather you run the command from the root or the package folder itself. We can probably join the workspaceRoot here to fix this. https://github.com/nrwl/nx/blob/master/packages/workspace/src/utilities/buildable-libs-utils.ts#L238

Happy to make a PR if that can help move it forward. In the meantime we will just only run the commands from the root folder.

Expected Behavior

The 2 commands should give the same results

GitHub Repo

No response

Steps to Reproduce

  1. Create a monorepo
  2. Create a project with typescript
  3. Add tsc runner following the documentation example
  4. run nx run project:build from root folder & nx build from the project folder
  5. One will build the files correctly the other will be a folder with just package.json

Nx Report

Node : 16.19.0
   OS   : darwin arm64
   yarn : 1.22.19

   nx               : 15.8.3
   lerna            : 6.5.1
   @nrwl/js         : 15.8.3
   @nrwl/jest       : 15.8.3
   @nrwl/linter     : 15.8.3
   @nrwl/workspace  : 15.8.3
   @nrwl/cli        : 15.8.3
   @nrwl/devkit     : 15.8.3
   @nrwl/tao        : 15.8.3
   typescript       : 4.6.2

Failure Logs

No failure just invalid behavior

Additional Information

No response

alexandrebodin avatar Mar 08 '23 08:03 alexandrebodin

Hey 👋

I would be happy to make a PR if that can help. Can you confirm the issue and would that you would be willing to accept a fix as described in the issue description ?

alexandrebodin avatar Mar 14 '23 16:03 alexandrebodin

That path is passed from here: https://github.com/nrwl/nx/blob/8c9ad0da69b76def41ef1af615d0795272a0b78f/packages/js/src/executors/tsc/tsc.impl.ts#L46-L49

There's a normalized options object, in which all paths are absolute. Removing the underscore should fix the issue. The raw _options object is also used further down, I'm not sure if that's intentional or a mistake too.

cutiful avatar Jul 05 '23 17:07 cutiful

+1 on this issue, I've been experiencing the same thing. Builds only succeed from the root directory. @cutiful @alexandrebodin I modified the following locally to use options rather than _options and can confirm that fixed the issue.

https://github.com/nrwl/nx/blob/8c9ad0da69b76def41ef1af615d0795272a0b78f/packages/js/src/executors/tsc/tsc.impl.ts#L46-L49

https://github.com/nrwl/nx/blob/8c9ad0da69b76def41ef1af615d0795272a0b78f/packages/js/src/executors/tsc/tsc.impl.ts#L69-L70

purvesta avatar Aug 14 '23 22:08 purvesta

This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs. If we missed this issue please reply to keep it active. Thanks for being a part of the Nx community! 🙏

github-actions[bot] avatar Feb 11 '24 00:02 github-actions[bot]

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

github-actions[bot] avatar Mar 29 '24 00:03 github-actions[bot]