Description
Describe the bug
Cannot import files aliased in the tsconfig paths. imports sometimes work for some files but often don't. I can't say i know why, but when the break the errors are cascading causing imports with aliased paths to break too and forcing the whole project to revert back to relative path imports
(Write your answer here.)
Did you try recovering your dependencies?
Yes
Which terms did you search for in User Guide?
https://create-react-app.dev/docs/adding-typescript/#troubleshooting
Environment
Environment Info:
current version of create-react-app: 5.0.0
running from /home/craft/.config/yarn/global/node_modules/create-react-app
System:
OS: Linux 5.14 Arch Linux
CPU: (8) x64 Intel(R) Xeon(R) CPU W3530 @ 2.80GHz
Binaries:
Node: 17.3.0 - /tmp/yarn--1640220951632-0.6230549606809872/node
Yarn: 1.22.17 - /tmp/yarn--1640220951632-0.6230549606809872/yarn
npm: 8.3.0 - /usr/bin/npm
Browsers:
Chrome: Not Found
Firefox: 95.0.2
npmPackages:
react: ^17.0.2 => 17.0.2
react-dom: ^17.0.2 => 17.0.2
react-scripts: 5.0.0 => 5.0.0
npmGlobalPackages:
create-react-app: Not Found
Steps to reproduce
- yarn create react-app sample --template typescript
- cd sample
- add
"baseUrl" : "."
and"paths" : { "@app/*": ["src/*"] }
options to thecompilerOptions
in tsconfig.json - cd src
- mkdir sub
- cd sub
- touch index.ts
- create a valid default export of any variable, constant, class, or function in the index.ts file just created
- cd ..
- add the line
import sub from '@app/sub';
to your App.tsx imports in the src/ directory - and try running yarn start from application root
Expected behavior
No errors
Actual behavior
Compiled with problems:
ERROR in ./src/App.tsx 6:0-27
Module not found: Error: Can't resolve '@app/sub' in '/home/craft/Projects/node/cra/src'
Reproducible demo
could not recreate the problem in https://codesandbox.io/s/trusting-morse-bs8tc?file=/src/App.tsx because it seams to work just fine there.