-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
TypeScript Executor Mangles Nested Subpaths #21699
Comments
We have reverted the patch to Nx and instead using aliases to link the files up to their correct locations. This behaves better with the jest executor which prefers to have the An example of the new solution we are using looks like the following: // packages/js/plugins/jest/local-registry.js
moudle.exports = exports = require('./src/plugins/jest/local-registry.js') // packages/js/plugins/jest/local-registry.d.ts
export * from './src/plugins/jest/local-registry' With that said, it would still be good to resolve this issue without a workaround as I am treating the packages outside the monorepo as out of scope since the solution to that is to change their module resolution to either node16/nodenext or bundler. |
…m to the outputs (#27429) <!-- 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 --> When re-mapping a TS path mapping like `"@foo/lib1/plugins/some-file": ["packages/lib1/src/plugins/some-file.ts"]`, it results in: ```json "@foo/lib1/plugins/some-file": [ "dist/packages/lib1/plugins/some-file", "dist/packages/lib1/src/plugins/some-file.ts" ] ``` The first path is wrong because it's missing the `src` directory, and the second one has a file extension that's not in the output. ## Expected Behavior <!-- This is the behavior we should expect with the changes in this PR --> When re-mapping a TS path mapping like `"@foo/lib1/plugins/some-file": ["packages/lib1/src/plugins/some-file.ts"]`, it should result in: ```json "@foo/lib1/plugins/some-file": [ "dist/packages/lib1/plugins/some-file", "dist/packages/lib1/src/plugins/some-file", "dist/packages/lib1/src/plugins/some-file.ts" ] ``` In this case, the second path would correctly point to the output. It doesn't have an extension, which allows the compiler to pick up the correct one. Note that while the first and third paths are still not valid for this specific use case, they could still be valid for other use cases, and in any case, they're still kept for backward compatibility. The util to re-map these paths is currently very generic and generates potentially valid paths. The invalid paths for a given use case won't throw an error as long as there's one that's valid. ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes #21699 (cherry picked from commit 89f6ad4)
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. |
Current Behavior
Importing a nested subpath export from a project in the same Nx workspace fails with a
cannot find module or its corresponding type declarations
typescript compilation error. This error is only present in the@nx/js:tsc
executor and is not present in the typescript language server or when running typescript compiler directly (tsc --noEmit --project ...
).Expected Behavior
The Nx TypeScript executor should produce valid paths when magically swapping in the output directory.
GitHub Repo
No response
Steps to Reproduce
We have a package with a nested subpath export for example
@nx/js/plugins/jest/local-registry
. Except rather than a file at that path we are following the guide from your typescript executor to define additional entrypoints, our subpath export lives in the source directory for examplepackages/js/src/plugins/jest/local-registry.ts
and we are relying on the generate exports field to correctly generate a./plugins/jest/local-registry
subpath export. This all works perfectly, where it falls apart is in the definition of the paths aliases for TypeScript, we have defined the following paths for the package:When running the TypeScript executor with the
NX_VERBOSE_LOGGING_PATH_MAPPINGS
environment variable we see the following output for the respective packages:In our case
dist/packages/js/plugins/jest/local-registry
is not a valid path anddist/packages/js/src/plugins/jest/local-registry.ts
has a bogus file extension.Nx Report
Failure Logs
No response
Package Manager Version
No response
Operating System
Additional Information
We are currently working around the issue by dropping the
.ts
file extension from our TypeScript path mappings for those nested subpath exports and applying the following patch:The text was updated successfully, but these errors were encountered: