GUJ Discussões   :   últimos tópicos   |   categorias   |   GUJ Respostas

Export Absolute Typescript - React

Olá, estou com problemas com imports absolutos no React com Typescript, sempre que rodo o projeto ele apaga as coisas que estão dentro do meu tsconfig.json, e me retorna esse erro no console compilerOptions.paths must not be set (aliased imports are not supported).

tsconfig.json:

{
  "compilerOptions": {
    "baseUrl": ".",
    "target": "es5",
    "paths": {
      "@Assets/*": ["./src/Assets/*"],
      "@Pages/*": ["./src/Pages/*"],
      "@Templates/*": ["./src/Templates/*"],
      "@atoms/*": ["./src/UI/atoms/*"],
      "@molecules/*": ["./src/UI/molecules/*"],
      "@organisms/*": ["./src/UI/organisms*"],
      "@UI/*": ["./src/UI/*"]
    },
    "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"
  },
  "include": ["src"]
}

package.json:

{
  "name": "myapp",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^5.11.4",
    "@testing-library/react": "^11.1.0",
    "@testing-library/user-event": "^12.1.10",
    "@types/jest": "^26.0.15",
    "@types/node": "^12.0.0",
    "@types/react": "^17.0.0",
    "@types/react-dom": "^17.0.0",
    "@types/react-icons": "^3.0.0",
    "@types/styled-components": "^5.1.18",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-icons": "^4.3.1",
    "react-scripts": "4.0.3",
    "styled-components": "^5.3.3",
    "typescript": "^4.1.2",
    "web-vitals": "^1.0.1"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "devDependencies": {
    "tsconfig-paths": "^3.12.0"
  }
}

Alguém consegue me ajudar a fazer esses imports absolutes funcionar?

Não manjo muito, mas tem um link que tem um exemplo de como fazer isso: Absolute paths with Create React App + Typescript (without ejecting) | by Gustavo Graeff | Medium

//