You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
cannot import modules in src aliased in tsconfig paths compilerOptions #11834
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
Also got this issue on my machine. VSCode read tsconfig.json and recognize the import path well, however, the compiler didn't and raise above error 'Module not found'
TS doesn't do any path remapping itself, neither does ts-loader or babel-loader. The paths option only tells TS about existing path mappings that you have to set up yourself. VSCode is able to understand this, because VSCode only reads the tsconfig. However, your webpack runtime doesn't actually use it for path mapping. In Webpack it's pretty easy to set up with the resolve.alias feature.
Activity
nhonreboot commentedon Jan 3, 2022
Also got this issue on my machine. VSCode read
tsconfig.jsonand recognize the import path well, however, the compiler didn't and raise above error 'Module not found'Josh-Cena commentedon Jan 12, 2022
TS doesn't do any path remapping itself, neither does
ts-loaderorbabel-loader. Thepathsoption only tells TS about existing path mappings that you have to set up yourself. VSCode is able to understand this, because VSCode only reads the tsconfig. However, your webpack runtime doesn't actually use it for path mapping. In Webpack it's pretty easy to set up with theresolve.aliasfeature.nhonreboot commentedon Jan 12, 2022
Yep..figure it out already. But is there any way to fix it without eject CRA or switching to Craco?
Josh-Cena commentedon Jan 12, 2022
I'm actually surprised CRA doesn't let you merge additional Webpack config... FWIW, the first thing I do when making a CRA project is ejecting :P
2p4b commentedon Jan 12, 2022
@Josh-Cena. thanks for checking out the issue. In the context of CRA it doesn't work as its suppose to. please check out.
https://github.com/facebook/create-react-app/blob/bb64e31a81eb12d688c14713dce812143688750a/packages/react-scripts/config/modules.js#L136
https://github.com/facebook/create-react-app/blob/bb64e31a81eb12d688c14713dce812143688750a/packages/react-scripts/config/webpack.config.js#L348
Josh-Cena commentedon Jan 12, 2022
Looking a few lines up, you see the actual aliases that CRA generates.
https://github.com/facebook/create-react-app/blob/bb64e31a81eb12d688c14713dce812143688750a/packages/react-scripts/config/modules.js#L65-L79
The only alias is
src=>paths.appSrcwhich is reasonable so you can always doimport Foo from 'src/components/Foowithout relative paths.exdj158 commentedon Sep 14, 2022
thanks,I added these changes on tsconfig.json,it worked
compilerOptions:{ "paths": { "appPath": ["./src"], "appSrc": ["./src"] }, "baseUrl": ".", }gtanchak commentedon Nov 27, 2022
I have added this type of path in tsconfig file
"paths": {"@app/*": ["src/*"]}and use this relative path to my routes file
import Register from "@app/pages/register";it's causing this type of error