risen228 / craco-alias

A craco plugin for automatic aliases generation for Webpack and Jest
MIT License
109 stars 11 forks source link

'Cannot parse tsconfig.extend.json' error #23

Closed fedorinoGore closed 3 years ago

fedorinoGore commented 3 years ago

Im following the readme instructions but constantly having error "Cannot parse tsconfig.extend.json" Option "debug: true" doesn't work, at least I don't see any additional info in the console

Here are my config files: craco.config.js

module.exports = {
    plugins: [
        {
            plugin: require('craco-alias'),
            options: {
                debug: true,
                source: 'tsconfig',
                tsConfigPath: './tsconfig.extend.json',
                baseUrl: './src'
            }
        }
    ],
    style: {
        postcss: {
            plugins: [require('tailwindcss'), require('autoprefixer')]
        }
    }
}

tsconfig.json

{
"extends": "./tsconfig.extend.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"
  },
  "include": [
    "src"
  ]
}

tsconfig.extend.json

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

Having this deps in package.json:

{
  ...
"@craco/craco": "^6.1.0",
"react-scripts": "4.0.1",
"craco-alias": "^2.1.1",
"typescript": "4.1.3"
}
katsimoto commented 3 years ago

tsconfig.extend.json is not valid, please check the syntax

fedorinoGore commented 3 years ago

@VyacheslavR could you please give me a hint - what's wrong with tsconfig.extend.json?

katsimoto commented 3 years ago

@fedorinoGore, you put commas at the end, if it was js, it would be ok, but in json it is not valid. Here is a valid example:

{
    "compilerOptions": {
        "baseUrl": "./src",
        "paths": {
            "@components/*": [
                "./components/*"
            ]
        }
    }
}
yomiAdenaike01 commented 3 years ago

Go to this file path craco-alias/plugin/pre-check/check-config-contents.js and then in the first try and catch add the err property to the string output just do what is says and then it will be correct, or you can put the file as json initially or put it through a JSON parser to check it for errors and then put it in the extend.json

renyuanz commented 3 years ago

beyond the ending commas, just be aware of removing all comments in the tsconfig.extend.json as comments are not allowed in the JSON file...

risen228 commented 3 years ago

I updated the message to make it easier to find the syntax error.

ui-yazan-abbas commented 2 years ago

@katsimoto Thanks!