In the default TypeScript based create-react-app
project, only the first TS error is shown when the project is built with react-scripts
but all errors are shown when running tsc
.
The project was initialized with create-react-app foo --typescript
and only src/index.tsx
was modified after initialization:
src/index.tsx src/index.tsx
console.log(typeof nonExistentVar);
console.log(typeof nonExistentVar);
console.log(typeof nonExistentVar2);
console.log(typeof nonExistentVar2);
export {};
package.json
export {};
{
"name": "foo",
"version": "0.1.0",
"private": true,
"dependencies": {
"@types/jest": "24.0.15",
"@types/node": "12.6.8",
"@types/react": "16.8.23",
"@types/react-dom": "16.8.5",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-scripts": "3.0.1",
"typescript": "3.5.3"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
tsconfig.json
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "preserve"
},
"include": [
"src"
]
}
npm start
shows only the first error:
Failed to compile.
C:/foo/src/index.tsx
TypeScript error in C:/foo/src/index.tsx(1,20):
Cannot find name 'nonExistentVar'. TS2304
> 1 | console.log(typeof nonExistentVar);
| ^
2 | console.log(typeof nonExistentVar2);
3 | export {};
And tsc
shows all errors at once:
src/index.tsx:1:20 - error TS2304: Cannot find name 'nonExistentVar'.
1 console.log(typeof nonExistentVar);
~~~~~~~~~~~~~~
src/index.tsx:2:20 - error TS2304: Cannot find name 'nonExistentVar2'.
2 console.log(typeof nonExistentVar2);
~~~~~~~~~~~~~~~
Found 2 errors.
How can I force start
and build
scripts to show all errors?