Src/main.tsx(4,62): error TS2345: Argument of type "Element" is not assignable to parameter of type "ReactNode". 9:26:17 AM: Property "children" is missing in type "Element" but required in type "ReactPortal"

Hi All a couple days ago it suddenly started failing on Building with the following error
9:26:12 AM: yarn run v1.22.19
9:26:12 AM: $ tsc && vite build
9:26:17 AM: src/main.tsx(4,62): error TS2345: Argument of type “Element” is not assignable to parameter of type “ReactNode”.
9:26:17 AM: Property “children” is missing in type “Element” but required in type “ReactPortal”.
9:26:17 AM: error Command failed with exit code 2. (Search results for '"non-zero exit code: 2"' - Netlify Support Forums)
9:26:17 AM: info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
9:26:17 AM: ​
9:26:17 AM: “build.command” failed
9:26:17 AM: ────────────────────────────────────────────────────────────────
9:26:17 AM: ​
9:26:17 AM: Error message
9:26:17 AM: Command failed with exit code 2: yarn build (Search results for '"non-zero exit code: 2"' - Netlify Support Forums)
9:26:17 AM: ​
9:26:17 AM: Error location
9:26:17 AM: In Build command from Netlify app:
9:26:17 AM: yarn build
9:26:17 AM: ​
9:26:17 AM: Resolved config
9:26:17 AM: build:
9:26:17 AM: command: yarn build
9:26:17 AM: commandOrigin: ui
9:26:17 AM: environment:
9:26:17 AM: - NETLIFY_BUILD_DEBUG
9:26:17 AM: - VITE_API_BASE_URL
9:26:17 AM: - VITE_MUI_LICENSE_KEY
9:26:17 AM: - VITE_X_RAPID_API_HOST
9:26:17 AM: - VITE_X_RAPID_API_KEY
9:26:17 AM: - VITE_X_RAPID_API_URL
9:26:17 AM: publish: /opt/build/repo/build
9:26:17 AM: publishOrigin: ui
9:26:24 AM: Build failed due to a user error: Build script returned non-zero exit code: 2

it is failing on the following line ReactDOM.createRoot(document.getElementById(‘root’)!).render(〈App / 〉
);
Any ideas?
Thanks

Hi @bm2, Thanks for the post and welcome to the Netlify Support Forums.

Kindly fix the TypeScript errors above in the file located at src/main.tsx and your application should build.
Let me know the outcome.
Thanks.

it is ok in local env it builds but in Netlify is not

@bm2 , yes it is true it will work on local development but not work on productions due to TypeScript / Lint configurations during builds.

When deploying applications on Netlify, your application will build for Production.

Even when you try to build your application on Local the same error will be thrown since builds are generally configured for production.

TypeScript errors prevent your application from building for production.

Thanks.

I am trying to build production in local and it works with no error
“build”: “tsc && vite build”,

even I revert to a couple of weeks back (it definitely worked) it still failed with the same message

Hi @bm2 , at this point the only suggestion to the issue is to fix the error as I originally highlighted since the problem that is causing the error is clearly stated in the build logs.
I can’t tell if you have done any updates to packages or other changes to your code which might be causing the problem.

However what I can do tell is that based on the build logs, the problem is not a Netlify problem but a TypeScript problem.
The problem is on line 4 in the src/main.tsx file.

9:26:17 AM: src/main.tsx(4,62): error TS2345: Argument of type “Element” is not assignable to parameter of type “ReactNode”.

If you are having a hard time fixing the TypeScript error, If possible you can also share a code snippet of the src/main.tsx file in order for me to understand what is happening as it clearly states that there is an Argument of type "Element" which is not assignable parameter of type "ReactNode"

Thanks.

I fixed the problem by adding the following to tsconfig.json

“paths”: {
“react”: [“./node_modules/@types/react”]
},

1 Like

Hi @bm2 , Good to know you were able to fix the problem.
Also thanks for sharing how you fixed the problem.