Type Error in Production Build: Variable 'x' Implicitly Has an 'any[]' Type
yunesco opened this issue · 3 comments
Issue Summary:
When attempting to create an optimized production build using Next.js version 14.0.3, a type error occurs during the linting and type validity check phase. The error specifically points to the file .contentlayer/generated/Hubs/_index.mjs at line 5, indicating a problem with the variable 'allHubs' having an implicitly assigned 'any[]' type.
AllHubs is being generated from a document type called "Hub" using ContentLayer.
Steps to Reproduce:
Use Next.js version 14.0.3.
Include the "next-contentlayer" package with version "^0.3.4".
Attempt to create an optimized production build.
Expected Behavior:
The production build should be created successfully without any linting or type errors.
Actual Behavior:
The build process fails with a type error in the file .contentlayer/generated/Hubs/_index.mjs at line 5, pointing to the variable 'allHubs' having an implicitly assigned 'any[]' type.
Environment:
Next.js version: 14.0.3
Node.js version: 20.9.0
Relevant dependencies: "next-contentlayer": "^0.3.4"
Additional Information:
This issue may be related to the interaction between Next.js version 14.0.3 and the "next-contentlayer" package. The error specifically occurs during the linting and type checking phase, impacting the successful creation of an optimized production build.
Actual Error:
.contentlayer/generated/Hubs/_index.mjs:5:14
Type error: Variable 'allHubs' implicitly has an 'any[]' type.
3 |
4 |
> 5 | export const allHubs = []
| ^
6 |
Hello!
I'm curious.
What does look like your tsconfig.json
file?
The issue was fixed by setting the strict to false in tsconfig.json
{
"compilerOptions": {
"esModuleInterop": true,
"skipLibCheck": true,
"target": "es2022",
"allowJs": true,
"resolveJsonModule": true,
"moduleDetection": "force",
"isolatedModules": true,
"forceConsistentCasingInFileNames": true,
"strict": false,
"noUncheckedIndexedAccess": true,
"checkJs": true,
"lib": ["dom", "dom.iterable", "ES2022"],
"noEmit": true,
"module": "ESNext",
"moduleResolution": "Bundler",
"jsx": "preserve",
"plugins": [{ "name": "next" }],
"incremental": true,
"baseUrl": ".",
"strictNullChecks": true,
"paths": {
"@/*": ["./src/*"],
"@root/*": ["*"],
"contentlayer/generated": ["./.contentlayer/generated"]
}
},
"include": [
".eslintrc.cjs",
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
"**/*.cjs",
"**/*.js",
".next/types/**/*.ts",
".contentlayer/generated"
],
"exclude": ["node_modules"]
}
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.