2

I'm trying to make the import file paths in my react app absolute.

(EDIT: I'm trying to make this:

import fetchAPI from "../../util/api" 

to this

import fetchAPI from "util/api"

)

I've seen solutions to this by using the jsconfig.json as such

{
  "compilerOptions": {
    "baseUrl": "src"
  },
  "include": ["src"]
}

The way I understand it, this only makes the file paths in .js files absolute. Unfortunately the wide majority of the files in the project are .jsx, is there a way to make the file paths in these absolute?

Thanks in advance :)

NiceRice
  • 29
  • 6

1 Answers1

1

A workaround is to change the target option to "target": "esnext".

And change the compilerOption to target React or react-native like "jsx": "preserve" or "jsx": "react" or "jsx": "react-native".

{
"compilerOptions": {
    "target": "esnext",
    "jsx": "react",
    "baseUrl": "src"
},
"exclude": [
    "node_modules",
    "**/node_modules/*"
]

}

traderjosh
  • 321
  • 5
  • 16