-
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
esbuild - paths from tsconfig.base.json do not work properly in the build output #20817
Comments
Let me know if there is something more I can do to help here out My short term fix has been to sort my "paths" config in tsconfig.base.json so that it has the longer in those situations at the top. This seems to work but isn't a great long term experience as Nx inserts into paths where it wants to so will be something we have to keep an eye on as new libs are added |
In my case, the issue was also happening with serve using @nx/js:node. I'm manually fixing the sort for the moment. |
@jelling I would recommend adding a quick script you can run to sort the paths by length (that’s what we did) every time you make Nx change (add a lib for example) it reorders the paths and you have to manually fix it up. Sorting by length with a script makes it trivial to fix the order - just my 2c |
Are you running this script manually or as part of the build process? If the latter, could you please show an example? Thanks. |
@th1nkful could you please share the script? |
@jelling sure! We just use
|
…27092) <!-- 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 there are workspace libraries with the following import paths: ``` @org/core @org/core/db @org/core/acme ``` They need to be sorted for the manifest such that matching finds the most specific first. The logic for this is currently based off whether an `*` exists, which doesn't work when the paths are specific. ## Expected Behavior <!-- This is the behavior we should expect with the changes in this PR --> Try to use `*` first and fallback to `/` to determine package prefix length. ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes #20817
…27092) <!-- 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 there are workspace libraries with the following import paths: ``` @org/core @org/core/db @org/core/acme ``` They need to be sorted for the manifest such that matching finds the most specific first. The logic for this is currently based off whether an `*` exists, which doesn't work when the paths are specific. ## Expected Behavior <!-- This is the behavior we should expect with the changes in this PR --> Try to use `*` first and fallback to `/` to determine package prefix length. ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes #20817 (cherry picked from commit a8dc251)
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
When using imports that have similar paths, esbuild will not output a manifest in main.js that properly allows importing all libs if they are ordered in certain orders in the tsconfig.base.json
For example:
The following paths in tsconfig.base.json will not order correctly in the manifest generated for here:
nx/packages/esbuild/src/executors/esbuild/lib/build-esbuild-options.ts
Line 246 in 32baa4d
Because @worklabs/db was first in paths, any imports when going through the hijacked _resolveFilename that were @worklabs/db/migrations or @worklabs/db/models were directed to @worklabs/db files which did not work
Interestingly, ts in VSCode found no issues with the order of paths. Nor did serve using @nx/js:node
Expected Behavior
If I have the above entries, they should be sorted so that the longer ones are first and do not mistakenly get matched to the wrong import
Locally, I was able to fix this behaviour by editing
getRegisterFileContent
function to sort by whole string length first like soGitHub Repo
No response
Steps to Reproduce
Nx Report
Failure Logs
Package Manager Version
8.11.0
Operating System
Additional Information
We picked this up while migrating to NX for "almost-monorepo" (code was all in one repo, but structure and tooling was lagging), so this wasn't something that was working before and now doesn't
The text was updated successfully, but these errors were encountered: