React Three Drei can't resolve react-dom/client 17.0.1 - reactjs

three version:^0.140.2
#react-three/fiber version:^8.0.19
#react-three/drei version:^9.11.0
node version:14.18.13
npm (or yarn) version: 1.22.17 (yarn)
react version:17.0.1
react-dom version:17.0.1
Problem description:
Implementing react three drei above my NextJS app getting an error when go to the page which import react three drei, like the following:
./node_modules/#react-three/drei/web/Html.js:3:0 Module not found: Can't resolve 'react-dom/client' Import trace for requested module: ./node_modules/#react-three/drei/index.js ./components/Model3D/ThreeDModel.js ./pages/new.js
Expected:
I go to 'new' page, then I can load 3d model with .glb format from HTML input tag using useGLTF
Relevant Code:
import React from 'react'
import { useGLTF } from '#react-three/drei/core/useGLTF'
import { OrbitControls } from '#react-three/drei'
import { parseImgUrl } from 'utils/common'
const Model1 = ({ threeDUrl }) => {
const loadedGltf = useGLTF(parseImgUrl(threeDUrl), true)
return (
<>
<primitive object={loadedGltf.scene} dispose={null} />
<OrbitControls />
<ambientLight />
</>
)
}
export { Model1 }
Suggested Solution:
At this time, I think root cause of the error is that my react three drei which I used don't supported react#17.0.1. I expected that previous react three drei version support react#17.0.1 then really wonder what specified version that support react#17.0.1 or maybe the error was caused by other things. Thank you for your support, that's always my pleasure.
This is the entire dependencies within package.json
{
"name": "paras-v2-landing",
"version": "0.1.0",
"private": true,
"type": "module",
"scripts": {
"dev": "next dev",
"dev:testnet": "PORT=8081 dotenv -e .env.testnet next dev",
"dev:mainnet": "PORT=8082 dotenv -e .env.mainnet next dev",
"build": "next build",
"start": "next start",
"lint": "next lint",
"format": "prettier --write .",
"prettier-check": "prettier --check .",
"prepare": "husky install"
},
"dependencies": {
"#draft-js-plugins/anchor": "^4.1.1",
"#draft-js-plugins/buttons": "^4.0.0",
"#draft-js-plugins/divider": "^4.1.1",
"#draft-js-plugins/editor": "^4.0.0",
"#draft-js-plugins/focus": "^4.1.0",
"#draft-js-plugins/image": "^4.0.0",
"#draft-js-plugins/inline-toolbar": "^4.1.0",
"#draft-js-plugins/linkify": "^4.1.0",
"#draft-js-plugins/static-toolbar": "^4.0.0",
"#draft-js-plugins/video": "^4.1.0",
"#react-three/drei": "^9.11.0",
"#react-three/fiber": "^8.0.19",
"#sentry/nextjs": "^6.12.0",
"#tailwindcss/line-clamp": "^0.3.1",
"axios": "^0.21.0",
"blurhash": "^1.1.3",
"cachios": "^3.0.0",
"capitalize": "^2.0.4",
"cids": "^1.1.5",
"compressorjs": "^1.0.7",
"croppie": "^2.6.5",
"draft-js": "^0.11.7",
"file-type": "^16.5.3",
"generate-avatar": "^1.4.10",
"javascript-time-ago": "^2.3.2",
"js-base64": "^3.5.2",
"js-cookie": "^2.2.1",
"jsbi": "^3.1.4",
"near-api-js": "^0.42.0",
"next": "^12.1.6",
"postcss": "^8.4.12",
"query-string": "^7.0.1",
"react": "^18.1.0",
"react-awesome-animated-number": "^1.0.6",
"react-blurhash": "^0.1.3",
"react-card-flip": "^1.1.5",
"react-content-loader": "^6.0.3",
"react-custom-scrollbars": "^4.2.1",
"react-dom": "^18.1.0",
"react-fast-marquee": "^1.1.3",
"react-google-recaptcha": "^2.1.0",
"react-hamburgers": "^1.0.0",
"react-hook-form": "^6.10.0",
"react-horizontal-scrolling-menu": "^2.7.0",
"react-infinite-scroll-component": "^5.1.0",
"react-intl": "^5.9.2",
"react-linkify": "^1.0.0-alpha",
"react-responsive-carousel": "^3.2.23",
"react-share": "^4.3.1",
"react-slick": "^0.28.1",
"react-tooltip": "^4.2.17",
"recharts": "^2.1.9",
"slick-carousel": "^1.8.1",
"swr": "^1.2.2",
"three": "^0.140.2",
"three-stdlib": "^2.10.1",
"uuid": "^8.3.2",
"zustand": "^3.1.3"
},
"devDependencies": {
"#next/bundle-analyzer": "^12.1.4",
"autoprefixer": "^10.4.4",
"dotenv-cli": "^4.1.1",
"eslint": "^7.30.0",
"eslint-config-next": "^11.0.1",
"eslint-config-prettier": "8.3.0",
"eslint-plugin-react-hooks": "^4.2.0",
"husky": "^7.0.0",
"lint-staged": "^11.1.2",
"postcss-import": "^13.0.0",
"postcss-preset-env": "^6.7.0",
"prettier": "2.4.1",
"pretty-quick": "^3.1.2",
"tailwindcss": "^3.0.23"
},
"license": "GPL-3.0",
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"*.{js,jsx}": [
"eslint --fix",
"git add"
],
"*.{html,css,less,ejs}": [
"git add"
]
}
}

Related

React / Next - TypeError: Cannot read properties of undefined (reading 'compat')

All of a sudden I am getting an issue when trying to run npm build.
The error I get is as follows (for all pages):
Error occurred prerendering page "/sharelink/Index". Read more: https://nextjs.org/docs/messages/prerender-error
TypeError: Cannot read properties of undefined (reading 'compat')
> Build error occurred
Error: Export encountered errors on following paths
Here is my package.json
{
"name": "nextjstemplate",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev -p 14009",
"build": "next build",
"start": "next start -p 14009",
"lint": "next lint",
"prepare": "husky install",
"postinstall": "npm run prepare",
"eslint": "eslint \"**/*.+(js|jsx|ts|tsx)\"",
"eslint:fix": "eslint --fix \"**/*.+(js|jsx|ts|tsx)\"",
"prettier": "prettier --check \"**/*.+(js|jsx|ts|tsx|json|yml|yaml|md|css|scss)\"",
"prettier:fix": "prettier --write \"**/*.+(js|jsx|ts|tsx|json|yml|yaml|md|css|scss)\"",
"pre-commit": "lint-staged"
},
"dependencies": {
"#emotion/react": "^11.10.0",
"#emotion/server": "^11.10.0",
"#emotion/styled": "^11.10.0",
"#hookform/resolvers": "^2.9.10",
"#mui/base": "^5.0.0-alpha.105",
"#mui/icons-material": "^5.10.6",
"#mui/material": "^5.11.3",
"#mui/system": "^5.10.10",
"#mui/x-date-pickers": "^5.0.8",
"#reduxjs/toolkit": "^1.8.6",
"axios": "^1.1.3",
"cookies-next": "^2.1.1",
"crypto": "^1.0.1",
"dompurify": "^2.4.3",
"html-react-parser": "^3.0.8",
"lottie-react": "^2.3.1",
"moment": "^2.29.4",
"next": "^12.3.0",
"next-progress": "^2.2.0",
"next-pwa": "5.5.4",
"nextjs-progressbar": "^0.0.14",
"notistack": "^2.0.8",
"pm2": "^5.2.2",
"prop-types": "^15.8.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-hook-form": "^7.40.0",
"react-redux": "^8.0.2",
"react-share": "^4.4.1",
"react-slick": "^0.29.0",
"react-toastify": "^9.1.1",
"sass": "^1.54.5",
"slick-carousel": "^1.8.1",
"yup": "^0.32.11"
},
"devDependencies": {
"#commitlint/cli": "^17.1.2",
"#commitlint/config-conventional": "^17.1.0",
"cypress": "^10.6.0",
"eslint": "8.22.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-next": "12.2.5",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-css-modules": "^2.11.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jsx-a11y": "^6.6.1",
"eslint-plugin-mui-path-imports": "^0.0.3",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-react": "^7.31.10",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-unused-imports": "^2.0.0",
"husky": "^8.0.1",
"lint-staged": "^13.0.3",
"prettier": "^2.7.1"
},
"lint-staged": {
"./*/**/*.{js,jsx,ts,tsx}": [
"npm run prettier:fix",
"npm run eslint:fix"
],
"*.{json,md}": [
"npm run prettier:fix"
]
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
}
}
Just to add to the above, the error seems more likely to be in relation to emotion.
error - TypeError: Cannot read properties of undefined (reading 'compat')
at /var/www/vhosts/staging-site.co.uk/node_modules/#emotion/react/dist/emotion-react.cjs.dev.js:190:29
at /var/www/vhosts/staging-site.co.uk/node_modules/#emotion/react/dist/emotion-element-b63ca7c6.cjs.dev.js:66:16
Any ideas on what is the cause for this issue?
This issue is caused by an update in #mui/styled-engine that apparently removes the CacheProvider from emotion.
You can force the resolution of this package to a previous version in the package.json as a workaround meanwhile the issue is not being fixed.
{
...,
"resolutions": {
"#mui/styled-engine": "5.11.0"
}
}
You can track the status of the issue here: https://github.com/mui/material-ui/issues/36096

how to fix this error when build next build

error occur when doing build next build, I have installed the module that was not found, but the error still appears
./node_modules/mdx-bundler/dist/client.js
Module not found: Package path ./compat/jsx-runtime.js is not exported from package /vercel/path0/node_modules/preact (see exports field in /vercel/path0/node_modules/preact/package.json)
this my package
{
"name": "x",
"version": "1.2.0",
"private": true,
"scripts": {
"develop": "vercel",
"start": "node ./scripts/next-remote-watch.js ./data",
"dev": "next dev",
"build": "next build && node ./scripts/generate-sitemap",
"serve": "next start",
"analyze": "cross-env ANALYZE=true next build",
"lint": "next lint --fix --dir pages --dir components --dir lib --dir layouts --dir scripts",
"prepare": "husky install"
},
"dependencies": {
"#mailchimp/mailchimp_marketing": "^3.0.65",
"esbuild": "^0.12.15",
"github-slugger": "^1.4.0",
"gray-matter": "^4.0.2",
"image-size": "1.0.0",
"isomorphic-unfetch": "^3.1.0",
"mdx-bundler": "^8.0.1",
"motion": "^10.4.0",
"next": "12.0.2",
"next-themes": "^0.0.14",
"preact": "^10.6.6",
"querystring": "^0.2.1",
"react": "^17.0.2",
"react-dom": "17.0.2",
"react-icons": "^4.3.1",
"reading-time": "1.3.0",
"rehype-autolink-headings": "^6.0.0",
"rehype-katex": "^6.0.0",
"rehype-prism-plus": "^1.1.0",
"rehype-slug": "^5.0.0",
"remark-footnotes": "^4.0.0",
"remark-gfm": "^2.0.0",
"remark-math": "^5.0.0",
"sharp": "^0.28.3",
"swr": "^1.1.2",
"unist-util-visit": "^4.0.0"
},
"devDependencies": {
"#next/bundle-analyzer": "12.0.2",
"#svgr/webpack": "^5.5.0",
"#tailwindcss/aspect-ratio": "^0.4.0",
"#tailwindcss/forms": "^0.4.0",
"#tailwindcss/line-clamp": "^0.3.0",
"#tailwindcss/typography": "^0.5.0",
"#types/react": "^17.0.14",
"#types/tailwindcss": "^2.2.0",
"#typescript-eslint/eslint-plugin": "^4.28.1",
"#typescript-eslint/parser": "^4.28.1",
"autoprefixer": "^10.4.0",
"cross-env": "^7.0.3",
"dedent": "^0.7.0",
"eslint": "^7.29.0",
"eslint-config-next": "12.0.2",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-prettier": "^3.3.1",
"file-loader": "^6.0.0",
"globby": "11.0.3",
"husky": "^6.0.0",
"inquirer": "^8.1.1",
"lint-staged": "^11.0.0",
"next-remote-watch": "^1.0.0",
"postcss": "^8.4.5",
"prettier": "2.2.1",
"socket.io": "^4.1.3",
"socket.io-client": "^4.1.3",
"tailwindcss": "^3.0.7",
"typescript": "^4.3.5",
"vercel": "^24.0.0"
},
"lint-staged": {
"*.+(js|jsx|ts|tsx)": [
"eslint --fix"
],
"*.+(js|jsx|ts|tsx|json|css|md|mdx)": [
"prettier --write"
]
}
}

I can't use new feature ES 2020 in my next.js app

I wanted to use a new feature of ES 2020 in my next.js so I used optional changes in my app. When I ran my code this error has occurred
Module parse failed: Unexpected token (50:191)
You may need an appropriate loader to handle this file type.
Then I ran this command
npm install --save-dev #babel/plugin-proposal-optional-chaining
but the problem still exists.
Then I decided to update babel/core to version 7, I updated it via this command
npx babel-upgrade --write
but the loader error still there and I don't have any idea. Here is my package.json file:
{
"name": "Karan",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"dev": "SET NODE_ENV=development && SET PORT=3001 && node server.js",
"build": "next build",
"prod-build": "next build",
"start": "SET NODE_ENV=production && SET PORT=8080 && node server.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"#ckeditor/ckeditor5-basic-styles": "^11.1.4",
"#ckeditor/ckeditor5-build-classic": "^12.4.0",
"#ckeditor/ckeditor5-font": "^11.2.2",
"#ckeditor/ckeditor5-paragraph": "^11.0.5",
"#ckeditor/ckeditor5-react": "^1.1.3",
"#fullpage/react-fullpage": "^0.1.17",
"#sentry/browser": "^4.6.6",
"#svgr/webpack": "^4.3.2",
"#zeit/next-css": "^1.0.1",
"#zeit/next-stylus": "^1.0.1",
"axios": "^0.18.1",
"express": "^4.17.1",
"global": "^4.4.0",
"jalaali-js": "^1.1.0",
"leaflet": "^1.5.1",
"moment-jalaali": "^0.8.3",
"moment-jalali": "^0.3.9",
"next": "^8.1.0",
"next-images": "^1.1.2",
"next-routes": "^1.4.2",
"npm": "^6.12.1",
"numeral": "^2.0.6",
"persianjs": "^0.4.0",
"pm2": "^3.5.1",
"prop-types": "^15.6.2",
"qs": "^6.8.0",
"react": "^16.9.0",
"react-bootstrap-star-rating": "^3.5.5-alpha.0.3",
"react-dom": "^16.9.0",
"react-leaflet": "^2.4.0",
"react-modal": "^3.9.1",
"react-paginate": "^5.2.4",
"react-persian-calendar": "^1.0.3",
"react-rating": "^2.0.4",
"react-redux": "^5.0.7",
"react-responsive": "^5.0.0",
"react-select": "^2.4.4",
"react-share": "^2.4.0",
"react-slick": "^0.23.1",
"react-star-ratings": "^2.3.0",
"react-toastify": "^4.3.0",
"redux": "^4.0.4",
"redux-devtools-extension": "^2.13.5",
"redux-logger": "^3.0.6",
"redux-thunk": "^2.3.0",
"stylus": "^0.54.5"
},
"devDependencies": {
"#babel/core": "^7.0.0",
"#babel/plugin-proposal-optional-chaining": "^7.9.0",
"cross-env": "^5.2.1",
"optimize-css-assets-webpack-plugin": "^5.0.3",
"poststylus": "^1.0.0"
}
}
Since i see that you are using next you need to add a .babelrc file beside your package.json and include the below content -
{
"presets": ["next/babel"],
"plugins": []
}
next/babel includes
preset-env
preset-react
preset-typescript
plugin-proposal-class-properties
plugin-proposal-object-rest-spread
plugin-transform-runtime
styled-jsx
An alternative approach would be to add something similar (including the preset/transforms you need for your application) in your package.json
,
"babel": {
"presets": [
"nano-react-app"
],
"plugins": [
[
"#babel/plugin-proposal-class-properties",
{
"loose": true
}
],
[
"#babel/plugin-transform-react-jsx",
{
"pragmaFrag": "React.Fragment"
}
]
]
}

react-native expo publish showing a white screen

I have a very strange behaviour with a react native app building with Expo Kit. Things can run local, but just show a white screen when I publish or build apk/ipa. Here is pcakage.json
{
"name": "ezymo",
"version": "0.1.0",
"private": true,
"devDependencies": {
"express": "^4.16.2",
"gulp": "^3.9.1",
"gulp-clean": "^0.3.2",
"gulp-connect": "^5.0.0",
"gulp-rename": "^1.2.2",
"gulp-replace": "^0.6.1",
"jest-cli": "^21.2.1",
"jest-expo": "^22.0.0",
"object-assign": "^4.1.1",
"react-native-scripts": "1.7.0",
"react-test-renderer": "16.0.0-beta.5",
"run-sequence": "^2.2.0",
"socket.io": "^2.0.3"
},
"main": "./node_modules/react-native-scripts/build/bin/crna-entry.js",
"scripts": {
"start": "react-native-scripts start",
"eject": "react-native-scripts eject",
"android": "react-native-scripts android",
"ios": "react-native-scripts ios",
"test": "node node_modules/jest/bin/jest.js --watch"
},
"jest": {
"preset": "jest-expo"
},
"dependencies": {
"axios": "^0.16.2",
"dateformat": "^3.0.2",
"events": "^1.1.1",
"expo": "^22.0.2",
"lodash.times": "^4.3.2",
"prop-types": "^15.6.0",
"react": "16.0.0-beta.5",
"react-native": "^0.49.5",
"react-native-camera": "^0.10.0",
"react-native-datepicker": "^1.6.0",
"react-native-modal": "^4.1.0",
"react-native-ratings": "^4.1.0",
"react-native-vector-icons": "^4.4.2",
"react-navigation": "^1.0.0-beta.22",
"react-redux": "^5.0.6",
"redux": "^3.7.2",
"redux-saga": "^0.15.6",
"redux-thunk": "^2.2.0",
"uuid": "^3.1.0",
"when": "^3.7.8"
}
}
It's very strange that didn't happen for my other projects. Anyone encounter before and any suggestions?

React native Android SyntaxError attempted to redefine property 'FileSystem'

I get the following error on my android device after upgrade react native to 0.46.1 .
I using expo to build react native project , i dont know how to fixed it , it take me a lot of time
this is my package.json:
{
"name": "my-project",
"version": "0.1.0",
"private": true,
"devDependencies": {
"babel-eslint": "^7.2.1",
"babel-jest": "19.0.0",
"babel-plugin-flow-react-proptypes": "^0.21.0",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-preset-react-native": "^1.9.1",
"babel-preset-react-native-stage-0": "^1.0.1",
"eslint": "^3.18.0",
"eslint-config-airbnb": "^14.1.0",
"eslint-plugin-babel": "^4.1.1",
"eslint-plugin-import": "^2.2.0",
"eslint-plugin-jsx-a11y": "^4.0.0",
"eslint-plugin-react": "^6.10.3",
"flow-bin": "^0.38.0",
"jest": "19.0.2",
"jest-expo": "1.0.1",
"react-native-scripts": "0.0.29",
"react-test-renderer": "^15.6.1"
},
"main": "./node_modules/react-native-scripts/build/bin/crna-entry.js",
"scripts": {
"start": "react-native-scripts start",
"eject": "react-native-scripts eject",
"android": "react-native-scripts android",
"ios": "react-native-scripts ios",
"test": "node node_modules/jest/bin/jest.js --watch"
},
"jest": {
"preset": "jest-expo"
},
"dependencies": {
"axios": "^0.16.1",
"expo": "^19.0.0-alpha.0",
"lodash.debounce": "^4.0.8",
"lodash.isempty": "^4.4.0",
"mobx": "^3.1.9",
"mobx-react": "^4.1.8",
"native-base": "2.2.1",
"qs": "^6.4.0",
"react": "16.0.0-alpha.12",
"react-native": "0.46.1",
"react-native-easy-grid": "^0.1.11",
"react-native-fs": "^2.3.3",
"react-native-modalbox": "^1.3.9",
"react-native-radio-buttons": "^0.14.0",
"react-native-storage": "^0.2.2",
"react-native-svg": "^5.3.0",
"react-navigation": "^1.0.0-beta.9",
"singleton": "^1.0.0",
"styled-components": "^1.4.6"
}
}

Resources