Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Typescript compiler does not stop when a error occured in next js

i want use nextjs beside typescript in my project. i used npx create-next-app --typescript(official way for add typescript to next). everything ok but when a typescript error occured e.g const st:string =3; compiler successfully run and i recieved error only in my IDE and compiler don't stop.i want when run npm run dev command compiler show error to me and then failed. I would be very grateful if anyone could help me

this is my tsconfig file

{
  "compilerOptions": {
    "target": "es5",
    "lib": ["dom", "dom.iterable", "esnext"],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve",
  },
  "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
  "exclude": ["node_modules"]
}
like image 841
Ali Ehyaie Avatar asked Dec 21 '25 20:12

Ali Ehyaie


1 Answers

if you want better intellisense to figure out what's going on, make sure you enable strictNullChecks: true and alwaysStrict: true

That will enhance your TSX experience

{
    "compilerOptions": {
        "target": "es5",
        "module": "esnext",
        "lib": ["ESNext", "DOM", "DOM.Iterable"],
        "declaration": true,
        "strict": true,
        "noImplicitAny": true,
        "strictNullChecks": true,
        "noImplicitThis": true,
        "alwaysStrict": true,
        "moduleResolution": "node",
        "noUnusedLocals": false,
        "noUnusedParameters": false,
        "jsx": "preserve",
        "downlevelIteration": true,
        "noImplicitReturns": true,
        "noFallthroughCasesInSwitch": true,
        "inlineSourceMap": true,
        "inlineSources": true,
        "experimentalDecorators": true,
        "strictPropertyInitialization": true,
        "baseUrl": ".",
        "allowJs": true,
        "skipLibCheck": true,
        "forceConsistentCasingInFileNames": true,
        "noEmit": true,
        "esModuleInterop": true,
        "resolveJsonModule": true,
        "isolatedModules": true,
        "paths": {
            "@/components/*": ["components/*"],
            "@/config/*": ["config/*"],
            "@/graphql/*": ["graphql/*"],
            "@/lib/*": ["lib/*"],
            "@/pages/*": ["pages/*"],
            "@/scripts/*": ["scripts/*"],
            "@/styles/*": ["styles/*"],
            "@/test/*": ["test/*"],
            "@/types/*": ["types/*"]
        }
    },
    "include": ["**/*.d.ts", "**/*.ts", "**/*.tsx", "**/*.js"],
    "exclude": ["node_modules", ".next", "out"]
}

like image 73
Andrew Ross Avatar answered Dec 23 '25 09:12

Andrew Ross



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!