Search code examples
reactjstsconfigreact-scripts

react jsconfig.json ignores paths


I have the following jsconfig.json in the root of my react app:

{
    "compilerOptions": {
      "baseUrl": "./src",
      "paths": {
        "rmv": ["components/rmv/*"]
      }
    }
  }

and there is a helper.jsx file located in ./src/components/rmv folder.

But my attempts to export it directly like that: import Helper from 'rmv/helper' fail with an error:

Failed to compile
Module not found: Can't resolve 'rmv/helper' 

Only import Helper from 'components/rmv/helper' works. Why? PS: I also tried:

"paths": {
        "rmv/*": ["components/rmv/*"]
      }

Does not work either.

Here is the minimum reproducible example: github.com/chapkovski/trouble_with_jsconfig

Specifically these lines: https://github.com/chapkovski/trouble_with_jsconfig/blob/e37c8c216eac0da7c70023f7fba47eea54973176/src/App.js#L4-L5


Solution

  • Paths are currently unavailable in apps made with create-react-app:

    https://github.com/facebook/create-react-app/issues/5645

    You may want to consider using rescripts to let you modify your configuration in CRA 2+ apps.