Question:
How to upload Nodejs 16.14.2 project in NextJS 12 to NodeJS 18.17.0?

Problem

I created my project using Nodejs 16 and Nextjs 12, but I wanted to update to Nodejs 18. So I did the steps above:


1- Removed my node_modules
2- Removed my .next folder
3- nvm use 18 on terminal
4- yarn (to install all dependencies)


When I finished, this process, I got an error for every component used in my pages folder, or even on a component inside a component:


The 'MYCOMPONENT' module cannot be used as a JSX component.

Its type '({ href, type, active, children }: MYCOMPONENTSPROPS) => Element' is not a valid JSX element type.

The type '({ href, type, active, children }: MYCOMPONENTSPROPS) => Element' cannot be assigned to the type '(props: any, deprecatedLegacyContext?: any) => ReactNode'.

The type 'Element' cannot be assigned to 'ReactNode'.

The 'children' property is missing in the 'Element' type but is required in the 'ReactPortal' type.ts(2786)

index.d.ts(175, 9): 'children' is declared here.


It didn't show any error on my project, but it kept showing on vs code.


My package.json is:


"dependencies": {

    "next": "12.2.3",

    "nookies": "^2.5.2",

    "react": "18.2.0",

    "react-dom": "18.2.0",

    "react-responsive": "^9.0.0",

    "redux-persist": "^6.0.0",

    "sass": "^1.54.0"

},

"devDependencies": {

    "@types/node": "18.6.3",

    "@types/react": "18.0.15",

    "@types/react-dom": "18.0.6",

    "eslint": "8.21.0",

    "eslint-config-next": "12.2.3",

    "prettier": "3.0.3",

    "typescript": "^5.2.2"

}


Solution

make to two steps:


update version nextjs and typescript


next@^12.3.1


typescript@^4.7.4


last:


and ctrl + shift + p


select typescript version -> 4.9.5



Suggested blogs:

>Fix: Strange compilation error with Typescript and Angular

>What if the property 'X' does not exist on type 'FastifyContext<unknown>'?

>How to get the type of a class property's getter/setter in TypeScript?

>How to assign multiple const variables in a single declaration in TypeScript?

>Type inference with 'as const' IN TypeScript

>Typescript Return argument: Tuple type or passed to rest parameter warning?

>Why Typescript does not allow a union type in an array?

>Narrow SomeType vs SomeType[]

>Create a function that convert a dynamic Json to a formula in Typescript

>How to destroy a custom object within the use Effect hook in TypeScript?

>How to type the values of an object into a spreadsheet in TypeScript?


Nisha Patel

Nisha Patel

Submit
0 Answers