jaredpalmer / tsdx

Zero-config CLI for TypeScript package development
https://tsdx.io
MIT License
11.2k stars 505 forks source link

Unable to override tsconfig.compilerOptions.moduleResolution #1168

Open zemse opened 1 year ago

zemse commented 1 year ago

Current Behavior

If I want to use moduleResolution as node16, currently tsdx ignores what is specified in tsconfig and uses legacy module resolution. This causes typescript errors.

The particular feature that I want to use is package.json exports. For this to work, the moduleResolution should be set to node16. By setting this, typescript errors in vscode disappear, however tsdx build does not succeed (and the error that it gives is similar to what vscode gives without node16 moduleResolution).

Example error:

(typescript) Error: /my/project/src/file/path.ts(5,34): semantic error TS2307: Cannot 
find module 'ethers/address' or its corresponding type declarations.

Here, ethers is a package, and address is defined as an export in it's package.json.

Expected behavior

It should build.

Suggested solution(s)

Additional context

Your environment


  System:
    OS: macOS 12.0.1
    CPU: (8) arm64 Apple M1
    Memory: 134.91 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 16.17.1 - ~/.nvm/versions/node/v16.17.1/bin/node
    Yarn: 1.22.19 - ~/.nvm/versions/node/v16.17.1/bin/yarn
    npm: 8.15.0 - ~/.nvm/versions/node/v16.17.1/bin/npm
  Browsers:
    Chrome: 109.0.5414.119
    Firefox: 89.0.1
    Safari: 15.1
  npmPackages:
    tsdx: ^0.14.1 => 0.14.1 
    typescript: ^4.6.3 => 4.8.3 
  npmGlobalPackages:
    typescript: 4.8.4
zemse commented 1 year ago

It seems this issue is caused in rollup-plugin-typescript2. The user's tsconfig is overridden and moduleResolution is set to legacy node resolution (relevant code).

I've locally tried to patch this. However, the build gets stuck forever. There may be a reason why this is overridden.

I've created an upsteam issue https://github.com/ezolenko/rollup-plugin-typescript2/issues/437.