create-react-app icon indicating copy to clipboard operation
create-react-app copied to clipboard

jsconfig.json compilerOptions paths doesn't work

Open Capricair opened this issue 1 year ago • 2 comments

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

Capricair avatar Oct 09 '23 07:10 Capricair

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 avatar Nov 04 '23 18:11 peterdinis

@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.

Capricair avatar Nov 14 '23 10:11 Capricair