weiran-zsd / dts-cli

Zero-config CLI for TypeScript package development
MIT License
440 stars 23 forks source link

Problem with "paths" in tsconfig configuration #126

Closed michelecocuccio closed 2 years ago

michelecocuccio commented 2 years ago

Hello. Thank for the awesome library. I am currently using paths in my tsconfig as I have a very complex structure folder. The project itself compiles perfectly but when it's bundled I get imports error (I am using the example folder to test the project).

Error: The following dependencies are imported but could not be resolved:

  store (imported by /Users/michelecocuccio/Documents/Michele/Projects/Simple React Lightbox/NEW/srl/simple-react-lightbox/dist/simple-react-lightbox.esm.js)
  store/reducers/srlSlice (imported by /Users/michelecocuccio/Documents/Michele/Projects/Simple React Lightbox/NEW/srl/simple-react-lightbox/dist/simple-react-lightbox.esm.js)
  utils (imported by /Users/michelecocuccio/Documents/Michele/Projects/Simple React Lightbox/NEW/srl/simple-react-lightbox/dist/simple-react-lightbox.esm.js)
  hooks (imported by /Users/michelecocuccio/Documents/Michele/Projects/Simple React Lightbox/NEW/srl/simple-react-lightbox/dist/simple-react-lightbox.esm.js)
  styledComponents/SRLLightboxSC (imported by /Users/michelecocuccio/Documents/Michele/Projects/Simple React Lightbox/NEW/srl/simple-react-lightbox/dist/simple-react-lightbox.esm.js)
  SRLComponents/SRLContainer (imported by /Users/michelecocuccio/Documents/Michele/Projects/Simple React Lightbox/NEW/srl/simple-react-lightbox/dist/simple-react-lightbox.esm.js)

Is there a way to make sure the paths are compiled correctly when the project is bundled?

Paths in tsconfig Project structure Dist folder

Your environment

  System:
    OS: macOS 12.0.1
    CPU: (8) x64 Intel(R) Core(TM) i7-7820HQ CPU @ 2.90GHz
    Memory: 39.71 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 16.13.0 - /usr/local/bin/node
    Yarn: 1.22.15 - ~/.yarn/bin/yarn
    npm: 8.1.0 - /usr/local/bin/npm
  Browsers:
    Chrome: 97.0.4692.71
    Firefox: 95.0.2
    Safari: 15.1
  npmPackages:
    dts-cli: ^1.1.5 => 1.1.5
    typescript: ^4.5.4 => 4.5.4
aladdin-add commented 2 years ago

have you tried @rollup/plugin-alias?

aladdin-add commented 2 years ago

and it also would be great if dts can auto read aliases from tsconfig.json => paths.

michelecocuccio commented 2 years ago

@aladdin-add thank you very much. I just tried but no luck :( I have also renamed all the path to be @/components/ adding the @ for example in order to avoid compatibility issues but I still have the same issues :(

aladdin-add commented 2 years ago

looks like rpt2 will read the paths in your tsconfig.json, while jest will not. so you just need to add your jest config. 😄

see the branch: https://github.com/weiran-zsd/dts-cli/tree/issue126