create-react-app
create-react-app copied to clipboard
jsconfig.json compilerOptions paths doesn't work
jsconfig.json
{
"compilerOptions": {
"paths": {
"@components": ["./src/components"]
}
}
}
import Test from "@components/test"
module not found, I make sure that there is the component src/components/test/index.js
Hi @Capricair . Update your jsconfig.json like this:
jsconfig.json
{
"compilerOptions": {
"target": "ES6",
"baseUrl": "./src",
"paths": {
"@components": ["./src/components"]
}
},
"include": ["src"]
}
Then you shouldn't have the problem: "Module not found"
@peterdinis Thanks
I found that the problem was with cra, it didn't have a way to add webpack's alias without eject, I added the alias to webpack using react-app-rewired's config-overrides.js, it works.
alias is often used by developers, I think cra should provide a way to add alias.