ng-packagr / ng-packagr

Compile and package Angular libraries in Angular Package Format (APF)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Esbuild incorrect path resolution

SebastianPodgajny opened this issue · comments

Type of Issue

[x] Bug Report
[ ] Feature Request

Description

Esbuild can resolve esm2002/*.mjs imports to tsconfig paths *.ts files

Error

Build failed with 11 errors:
../../../../libs/utils/utils/src/index.ts:1:14: ERROR: Could not resolve "./lib/ngrx-utils"
../../../../libs/utils/utils/src/index.ts:2:14: ERROR: Could not resolve "./lib/rt-error"
../../../../libs/utils/utils/src/index.ts:3:14: ERROR: Could not resolve "./lib/with-default-value"
../../../../libs/utils/utils/src/index.ts:4:14: ERROR: Could not resolve "./lib/strictly-typed-utils"
../../../../libs/utils/utils/src/index.ts:5:14: ERROR: Could not resolve "./lib/interfaces"
...

Esbuild versobe output

⬥ [VERBOSE] Resolving import "@scope/utils" in directory "/Users/sebastianpodgajny/WebStorm/scope/dist/libs/common/esm2022/lib" of type "import-statement"

  Checking for package alias matches
    Failed to find any package alias matches
  Read 33 entries for directory "/Users/sebastianpodgajny/WebStorm/scope/dist/libs/common/esm2022/lib"
  No "browser" map found in directory "/Users/sebastianpodgajny/WebStorm/scope/dist/libs/common/esm2022/lib"
  Searching for "@scope/utils" in "node_modules" directories starting from "/Users/sebastianpodgajny/WebStorm/scope/dist/libs/common/esm2022/lib"
    Matching "@scope/utils" against "paths" in "/Users/sebastianpodgajny/WebStorm/scope/tsconfig.json"
      Using "/Users/sebastianpodgajny/WebStorm/scope" as "baseURL"
      Found an exact match for "@scope/utils" in "paths"
      Attempting to load "/Users/sebastianpodgajny/WebStorm/scope/libs/utils/utils/src/index.ts" as a file
        Checking for file "index.ts"
        Found file "index.ts"
  Read 3 entries for directory "/Users/sebastianpodgajny/WebStorm/scope/libs/utils/utils/src"
  This import is under the effect of "/Users/sebastianpodgajny/WebStorm/scope/libs/utils/utils/tsconfig.json"
  Primary path is "/Users/sebastianpodgajny/WebStorm/scope/libs/utils/utils/src/index.ts" in namespace "file"

My current workaround is to add external: ['@scope/*'], to esbuild config

Expected Behaviour

Esbuild should not resolve TS files during fesm transform

Version Information

$ node_modules/.bin/ng-packagr --version
ng-packagr:            18.0.0-next.3
@angular/compiler:     17.3.0
typescript:            5.4.5

Please include all version numbers that might be relevant, e.g. third-party libraries

esbuild disables the paths when resolving from inside node_modules, but this path is in a dist directory so that rule doesn't apply:

https://github.com/evanw/esbuild/blob/70893e4d89bab1dbf2d512593f9e4d5bcb1f76bf/internal/resolver/resolver.go#L1107-L1118

I suppose an explicit tsconfig override may need to be specified to make any ambient tsconfig field invisible to esbuild.

@SebastianPodgajny, can you try to put tsconfigRaw: {}, in the esbuild options and see if that fixes the problem.

Yup tsconfigRaw: {}, fixed the issue 🙇🏻

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

This action has been performed automatically by a bot.