Modules resolved absolutely against `src` are treated as external: support TS Paths aliases
See original GitHub issueCurrent Behavior
Running tsdx create
initializes a tsconfig.json
with absolute module resolution relative to the src
directory. I have VS Code configured to prefer absolute paths if possible when importing modules, so if I have a module like…
src/foo.ts
export const foo = () => 'bar';
And I type
foo()
and hit Tab, VS Code will add the following import:
import { foo } from 'foo';
This is valid and properly resolved by Typescript. However, if I compile my library, the current Rollup behavior assumes that foo
is an external module and doesn’t include it in the bundle.
Expected behavior
I would expect my local modules to be included in my bundle regardless of whether I imported them using ‘absolute’ resolution as above,
OR
I would expect tsdx
to not initialize tsconfig.json
with resolution rules which would lead me to believe importing modules relative to src
is a valid thing to do.
Suggested solution(s)
Either fix the external modules rules to properly understand local src
-based resolution, or remove the default src
resolution rules from tsconfig.json
to avoid confusing users.
Additional context
I probably hit this more often than most because I have configured my editor to prefer absolute path resolutions if available.
Your environment
Software | Version(s) |
---|---|
TSDX | 0.5.7 |
TypeScript | 3.4.3 |
Browser | N/A |
npm/Yarn | NPM 6.2.0 |
Operating System | Windows 10 |
Issue Analytics
- State:
- Created 4 years ago
- Reactions:16
- Comments:34 (3 by maintainers)
Top GitHub Comments
Since using
babel-plugin-module-resolver
does not actually correctly transform the generated*.d.ts
, I was able to create a workaround (customizing tsdx.config.js) to use ts-transform-paths and ttypescriptI am still debating if this is maintainable (I do really like the aliases), but thought I would post here in case someone has a better approach.
This was a great solution. Thank you @ankit. The key for me was to discover that the code above is only half of the equation. The other half is that tsconfig.json needs a compilerOptions.plugins entry for @zerollup/ts-transform-paths. Docs reference.