Closed ildar-icoosoft closed 4 years ago
Duplicate of #91 and issues labeled with TS Paths Aliases
Can read my summary of the situation in https://github.com/jaredpalmer/tsdx/issues/91#issuecomment-597989579, but I'll address some of the points here:
And absolute paths works if I run
npm run build
ornpm start
It actually doesn't work, all absolute imports get treated as externals, so the build output will be very broken.
Give the opportunity to use absolute paths in tests. Or take away the opportunity to use relative paths in
/src
folder
That's the topic of #91 et al. There is a workaround listed there, but it is fairly complex because you have to configure tsconfig.json
, .babelrc
, and jest.config.js
to get it to work.
Unfortunately the incorrect use of paths
is very common with TS users as I've linked to in the summary and those patterns made their way into the templates too 😕 .
I'm planning to remove them and potentially add full support for aliases at a later date. They are fundamentally broken, but they've been around for a while (I didn't write them), so doing so is potentially breaking, but we've got a few breaking changes already lined up so it'll be a bit (maybe v0.15?).
As it's a template change, I might be able to release as patch in v0.13.x (which has been mostly about templates) though, pending if you consider the templates to be an "API" or not.
Current Behavior
npm run test failed because of absolute import path aliases in tested code.
Steps to reproduce the error:
npx tsdx create mylib
(select "react" option)/src/config.ts
with following content:export const a = 1;
/src/index.tsx
file. Here is my/src/index.tsx
file content:// Delete me export const Thing = () => { console.log(a); return
"paths": { "": ["src/", "node_modules/*"] },