You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When building with the tsc executor, a temporary tsconfig file gets generated for you in {workspaceRoot}/tmp/{relativeProjectRoot}
This temporary tsconfig file is meant to use the tsconfig extends syntax to extend the tsconfig in your project root with some custom behavior based on your build settings
The exact value for the extends field is calculated in readTsConfigWithRemappedPathshere
And ``readTsConfigWithRemappedPaths` then calculated the exact path here
The bug
Note that for the value of extends to be calculated correctly in readTsConfigWithRemappedPaths, you have two options:
Make both paths (dirnameTsConfig, tsConfig) absolute
Make both paths relative to workspaceRoot
However, instead, right now dirnameTsConfig is turned into a relative path while tsConfig is kept as an absolute path (remember we normalized it here)
This results in the value of generatedTsConfig.extends to be incorrect, causing builds to fail
Expected Behavior
The paths should either both be absolute, or both be relative.
The easiest way to do this was to pass in the relative path into the checkDependencies function (since the tsConfig variable is not accessed anywhere except to calculate generatedTsConfig.extends), but changing dirnameTsConfig to always be absolute would also be okay
Builds seems to work fine for me on my repo.... how come you can reproduce it?
The reason this error wasn't caught before is presumably because if the extends path points to an invalid path, builds will still work if they were going to work with the default tsc configuration.
Notably, if you add console.log(tsConfig)here, you can see that these builds actually result in the following error that gets supressed
errors: [{file: undefined,start: undefined,length: undefined,messageText: "Cannot read file '/home/user/Documents/git/my-project/tsconfig.lib.json'.",category: 1,code: 5083,reportsUnnecessary: undefined,reportsDeprecated: undefined},{file: undefined,start: undefined,length: undefined,messageText: `No inputs were found in config file 'tsconfig.json'. Specified 'include' paths were '["**/*"]' and 'exclude' paths were '[]'.`,category: 1,code: 18003,reportsUnnecessary: undefined,reportsDeprecated: undefined}],
Reliably causing an actual build failure
Although these builds always have a configuration error, as I mentioned that doesn't always actually lead to a build error
error TS5090: Non-relative paths are not allowed when 'baseUrl' is not set. Did you forget a leading './'?
Cannot read file '/home/user/Documents/git/my-project/tsconfig.lib.json'
Package Manager Version
pnpm 9.6.0
Operating System
macOS
Linux
Windows
Other (Please specify)
Additional Information
No response
The text was updated successfully, but these errors were encountered:
SebastienGllmt
changed the title
Uses the wrong extends path when generated temporary tsconfig
@nx/js:tsc - wrong extends path used when generated temporary tsconfig
Oct 6, 2024
…ile for incremental builds (#29121)
<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->
<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->
<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->
## Current Behavior
<!-- This is the behavior we have today -->
## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->
## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->
Fixes#28316
Current Behavior
Background
When building with the
tsc
executor, a temporary tsconfig file gets generated for you in{workspaceRoot}/tmp/{relativeProjectRoot}
This temporary tsconfig file is meant to use the tsconfig
extends
syntax to extend the tsconfig in your project root with some custom behavior based on your build settingsex:
The code
Internally, this executor is called here
The first thing it does is take the tsconfig path in your executor's configuration and normalizes it. For example
will turn the relative
tsConfig
path into'/home/user/Documents/git/my-project/packages/backend/db/tsconfig.lib.json'
This new absolute path is then passed down to create the temporary tsconfig file in the following steps
checkDependencies
herecheckDependencies
callscreateTmpTsConfig
hereextends
field is calculated inreadTsConfigWithRemappedPaths
hereThe bug
Note that for the value of
extends
to be calculated correctly in readTsConfigWithRemappedPaths, you have two options:dirnameTsConfig
,tsConfig
) absoluteworkspaceRoot
However, instead, right now
dirnameTsConfig
is turned into a relative path whiletsConfig
is kept as an absolute path (remember we normalized it here)This results in the value of
generatedTsConfig.extends
to be incorrect, causing builds to failExpected Behavior
The paths should either both be absolute, or both be relative.
The easiest way to do this was to pass in the relative path into the
checkDependencies
function (since thetsConfig
variable is not accessed anywhere except to calculategeneratedTsConfig.extends
), but changingdirnameTsConfig
to always be absolute would also be okayGitHub Repo
https://github.com/SebastienGllmt/nx-tsc-repro
Steps to Reproduce
See repro README
Builds seems to work fine for me on my repo.... how come you can reproduce it?
The reason this error wasn't caught before is presumably because if the
extends
path points to an invalid path, builds will still work if they were going to work with the default tsc configuration.Notably, if you add
console.log(tsConfig)
here, you can see that these builds actually result in the following error that gets supressedReliably causing an actual build failure
Although these builds always have a configuration error, as I mentioned that doesn't always actually lead to a build error
nx build
Nx Report
Failure Logs
Package Manager Version
pnpm 9.6.0
Operating System
Additional Information
No response
The text was updated successfully, but these errors were encountered: