next.js
next.js copied to clipboard
Type error: PageComponent/LayoutComponent is declared but never used
Verify canary release
- [X] I verified that the issue exists in the latest Next.js canary release
Provide environment information
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 22.1.0: Sun Oct 9 20:15:09 PDT 2022; root:xnu-8792.41.9~2/RELEASE_ARM64_T6000
Binaries:
Node: 16.17.0
npm: 8.15.0
Yarn: 1.22.19
pnpm: N/A
Relevant packages:
next: 13.0.0
eslint-config-next: 13.0.0
react: 18.2.0
react-dom: 18.2.0
What browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
Describe the Bug
When adding "noUnusedLocals": true
to tsconfig.json and running a type-check with npx tsc
(or next build
), it fails due to declared but unused types:
.next/types/app/layout.ts:17:6 - error TS6196: 'PageComponent' is declared but never used.
17 type PageComponent = (props: PageProps) => React.ReactNode | Promise<React.ReactNode>
~~~~~~~~~~~~~
.next/types/app/page.ts:18:6 - error TS6196: 'LayoutComponent' is declared but never used.
18 type LayoutComponent = (props: LayoutProps) => React.ReactNode | Promise<React.ReactNode>
~~~~~~~~~~~~~~~
Expected Behavior
No type errors.
Link to reproduction
https://github.com/richardkall/next-bug-repro
To Reproduce
- Clone repo.
- Run
npm install
- Run
npm run build
Was able to solve this adding ".next"
to the "exclude"
arrray on tsconfig.json
.
{
"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",
"incremental": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"baseUrl": "./",
"paths": {
"tina-types": [
".tina/__generated__/types.ts"
],
"tina-client": [
".tina/__generated__/client"
]
},
"plugins": [
{
"name": "next"
}
]
},
"include": [
"**/*.ts",
"**/*.tsx",
"next-env.d.ts",
".next/types/**/*.ts",
".tina/__generated__/types.ts",
".tina/config.tsx"
],
"exclude": [
"node_modules",
".next",
]
}
Confirming the problem and the solution above:
Was able to solve this adding ".next" to the "exclude" array on tsconfig.json.
https://github.com/vercel/next.js/issues/41901#issuecomment-1295404567
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.