0

I try to use aliases for my project. After starting the app the paths object gets removed and no alias is working. This is my current simple tsconfig.json:

{
  "compilerOptions": {
    "target": "es5",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noFallthroughCasesInSwitch": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react-jsx",
    "baseUrl": "src",
    "paths": {
      "@styles/*": ["styles/*"],
      "@components/*": ["components/*"]
    }
  },
  "include": [
    "src"
  ]
}

After starting it looks like this:

{
  "compilerOptions": {
    "target": "es5",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noFallthroughCasesInSwitch": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react-jsx",
    "baseUrl": "src"
  },
  "include": [
    "src"
  ]
}

My console shows this error message:
enter image description here

I also tried to move the paths to tsconfig.paths.json and extend the tsconfig.json.

// tsconfig.json
{
  "extends": "./tsconfig.paths.json",
  "compilerOptions": {
     ...
     "baseUrl": "src"
  }
}

// tsconfig.paths.json
{
    "compilerOptions": {
        "paths": {
            "@styles/*": ["./styles/*"],
            "@components/*": ["./components/*"]
        }
    }
}

My third attemnt was to use craco which also doesn't worked out.

UPDATE
restarting VSC and the server did the trick for me. I get it to work with craco.

MrDeibl
  • 157
  • 1
  • 10
  • According to [this answer](https://stackoverflow.com/a/68778994/3083470) (and the error message) path aliases are no longer supported. You can try to check out the linked workaround. – Taxel Oct 25 '21 at 09:11
  • yes i already read about this so i tried it with craco but it still doesn't work. I will try it again. – MrDeibl Oct 25 '21 at 09:53

0 Answers0