I recently upgraded from Material UI v4 to v5. It seems there is some kind of incompatibility with my Jest tests since now I get the following error when attempting to render a TextField. The test runs fine if I use the component from MUI v4. The component renders fine when viewing the page in the browser.
Error: Uncaught [TypeError: Cannot read properties of undefined (reading ‘setAttribute’)]
at reportException (/home/node_modules/jest-config/node_modules/jsdom/lib/jsdom/living/helpers/runtime-script-errors.js:66:24)
at innerInvokeEventListeners (/home/node_modules/jest-config/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:341:9)
at invokeEventListeners (/home/node_modules/jest-config/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:274:3)
at HTMLUnknownElementImpl._dispatch (/home/node_modules/jest-config/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:221:9)
at HTMLUnknownElementImpl.dispatchEvent (/home/node_modules/jest-config/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:94:17)
at HTMLUnknownElement.dispatchEvent (/home/node_modules/jest-config/node_modules/jsdom/lib/jsdom/living/generated/EventTarget.js:231:34)
at Object.invokeGuardedCallbackDev (/home/node_modules/react-dom/cjs/react-dom.development.js:4210:16)
at invokeGuardedCallback (/home/node_modules/react-dom/cjs/react-dom.development.js:4274:31)
at reportUncaughtErrorInDEV (/home/node_modules/react-dom/cjs/react-dom.development.js:22737:5)
at captureCommitPhaseError (/home/node_modules/react-dom/cjs/react-dom.development.js:27078:5) TypeError: Cannot read properties of undefined (reading ‘setAttribute’)
at /home/node_modules/#emotion/react/dist/emotion-react.cjs.dev.js:206:12
console.error
The above error occurred in the <EmotionGlobal> component:
at /home/node_modules/#emotion/react/dist/emotion-element-e89f38a3.cjs.dev.js:64:23
at GlobalStyles (/home/node_modules/#mui/styled-engine/node/GlobalStyles/GlobalStyles.js:28:5)
at GlobalStyles
at InputBase (/home/node_modules/#mui/material/node/InputBase/InputBase.js:251:44)
at OutlinedInput (/home/node_modules/#mui/material/node/OutlinedInput/OutlinedInput.js:135:44)
at div
at /home/node_modules/#emotion/react/dist/emotion-element-e89f38a3.cjs.dev.js:64:23
at FormControl (/home/node_modules/#mui/material/node/FormControl/FormControl.js:111:44)
at /home/node_modules/#emotion/react/dist/emotion-element-e89f38a3.cjs.dev.js:64:23
at TextField (/home/node_modules/#mui/material/node/TextField/TextField.js:107:44)
at div
at /home/node_modules/#emotion/react/dist/emotion-element-e89f38a3.cjs.dev.js:64:23
at Box (/home/node_modules/#mui/system/createBox.js:41:41)
at div
at /home/node_modules/#emotion/react/dist/emotion-element-e89f38a3.cjs.dev.js:64:23
at Box (/home/node_modules/#mui/system/createBox.js:41:41)
at form
at CreateNewCVForm (/home/src/project/sciencv/static/sciencv/js/index/CreateNewCVForm.js:16:41)
at div
at /home/node_modules/#emotion/react/dist/emotion-element-e89f38a3.cjs.dev.js:64:23
at Box (/home/node_modules/#mui/system/createBox.js:41:41)
at div
at /home/node_modules/#emotion/react/dist/emotion-element-e89f38a3.cjs.dev.js:64:23
at CVListPage (/home/src/project/sciencv/static/sciencv/js/CVListPage.js:77:
Here is my package.json. I believe I upgraded to latest version of the various libraries that are being used to run the tests. I tried passing in the required / non-required attributes that are used by the component.
"devDependencies": {
"#babel/core": "^7.16.0",
"#babel/plugin-proposal-class-properties": "^7.16.0",
"#babel/plugin-proposal-optional-chaining": "^7.16.0",
"#babel/plugin-proposal-private-methods": "^7.16.0",
"#babel/plugin-transform-react-jsx": "^7.16.0",
"#babel/plugin-transform-react-jsx-self": "^7.16.0",
"#babel/preset-env": "^7.16.4",
"#babel/preset-react": "^7.16.0",
"#emotion/react": "^11.9.0",
"#emotion/styled": "^11.8.1",
"#material-ui/core": "^4.12.4",
"#mui/icons-material": "^5.8.3",
"#mui/lab": "^5.0.0-alpha.83",
"#mui/material": "^5.8.1",
"#mui/styles": "^5.8.0",
"#testing-library/jest-dom": "^5.16.4",
"#testing-library/react": "^13.3.0",
"axios": "^0.21.4",
"babel-eslint": "^10.1.0",
"babel-loader": "^8.2.3",
"clean-webpack-plugin": "^2.0.1",
"clone": "^2.1",
"css-loader": "^2.1.1",
"cssnano": "^4.1.10",
"date-fns": "^2.28.0",
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.15.0",
"eslint-config-standard": "^14.1.1",
"eslint-loader": "^3.0.4",
"eslint-plugin-import": "^2.25.3",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^4.3.1",
"eslint-plugin-standard": "^4.1.0",
"file-loader": "^4.2.0",
"jest": "^27.3.1",
"jest-teamcity-reporter": "^0.9.0",
"loglevel": "^1.7.1",
"marked": "^1.2.9",
"mini-css-extract-plugin": "^0.5.0",
"optimize-css-assets-webpack-plugin": "^5.0.1",
"prettier": "^2.4.1",
"react": "^18.1.0",
"react-dom": "^18.1.0",
"react-test-renderer": "^18.1.0",
"reactstrap": "^8.10.1",
"regenerator-runtime": "^0.13.9",
"resolve-url-loader": "^3.1.2",
"sass": "^1.43.4",
"terser-webpack-plugin": "^1.4.3",
"url-loader": "^3.0.0",
"webpack": "^4.46.0",
"webpack-bundle-tracker": "^0.4.3",
"webpack-cli": "^3.3.11",
"webpack-merge": "^4.2.1"
}
Related
I'm using visual studio code with node v18.
I use structuredClone in my application and it runs fine but when it comes to running a test I get
"ReferenceError: structuredClone is not defined"
I don't know how mocha works, but is it for some reason using an older version of node or is there some other dependency creating an issue?
"dependencies": {
"#sendgrid/mail": "^7.6.2",
"#types/chai": "^4.3.1",
"#types/express": "^4.17.13",
"#types/mocha": "^9.1.1",
"#types/node": "^18.0.0",
"#types/npm": "^7.19.0",
"bcrypt": "^5.0.1",
"body-parser": "^1.19.2",
"chai": "^4.3.6",
"connect-flash": "^0.1.1",
"cookie-parser": "^1.4.6",
"dotenv": "^16.0.0",
"eventemitter2": "^6.4.5",
"express": "^4.17.3",
"express-validator": "^6.14.0",
"jsdom": "^20.0.0",
"jsonwebtoken": "^8.5.1",
"marked": "^4.0.12",
"memory-cache": "^0.2.0",
"mocha": "^10.0.0",
"mssql": "^8.0.2",
"sanitize-html": "^2.7.0",
"validator": "^13.7.0",
"xsg.spider": "file:./../spider"
},
"devDependencies": {
"#types/bcrypt": "^5.0.0",
"#types/connect-flash": "^0.0.37",
"#types/cookie-parser": "^1.4.2",
"#types/dompurify": "^2.3.3",
"#types/jsdom": "^16.2.14",
"#types/jsonwebtoken": "^8.5.8",
"#types/marked": "^4.0.3",
"#types/memory-cache": "^0.2.2",
"#types/mssql": "^7.1.5",
"#types/passport-local": "^1.0.34",
"#types/sanitize-html": "^2.6.2",
"#types/validator": "^13.7.2",
"nyc": "^15.1.0",
"ts-node": "^10.7.0",
"typescript": "^4.6.4"
}
It's probably a bug, as a turnaround to deep clone your object, you can use JSON.parse & JSON.stringify:
if (global.structuredClone)
clonedObject = structuredClone(object)
else
clonedObject = JSON.parse(JSON.stringify(object))
I have used mongoose package in my nest project but when I am trying to build the project using npm run build.Then its throwing below error in my console:
node_modules/mongoose/node_modules/mongodb/mongodb.d.ts:34:15 - error TS2305: Module '"tls"'
has no exported member 'TLSSocketOptions'.
34 import type { TLSSocketOptions } from 'tls';
I have even updated the mongoose package to the latest version.Then also I am getting the same error:
Below are my dependencies inside package.json file:
"dependencies": {
"#apollo/gateway": "^0.38.0",
"#google-cloud/translate": "^6.2.1",
"#nestjs/common": "^8.0.6",
"#nestjs/core": "^8.0.6",
"#nestjs/cqrs": "^8.0.0",
"#nestjs/graphql": "^8.0.2",
"#nestjs/microservices": "^8.0.6",
"#nestjs/mongoose": "^9.0.3",
"#nestjs/platform-express": "^8.0.6",
"#types/luxon": "^1.15.1",
"apollo-server-express": "^2.25.2",
"bunyan": "^1.8.12",
"bunyan-rotating-file-stream": "^1.6.3",
"connect-redis": "^3.4.1",
"consul": "^0.40.0",
"device-detector-js": "^3.0.3",
"elasticsearch": "^16.2.0",
"express-session": "^1.16.2",
"firebase-admin": "^9.4.2",
"graphql": "^14.7.0",
"graphql-tools": "^4.0.4",
"json-rules-engine": "^3.1.0",
"kafkajs": "^1.15.0",
"lodash": "^4.17.21",
"luxon": "^1.16.0",
"moneysafe": "^2.2.1",
"mongodb": "^3.5.9",
"mongoose": "^6.3.0",
"nestjs-i18n": "^8.1.1",
"node-wit": "^6.0.0",
"reflect-metadata": "^0.1.12",
"rimraf": "^2.6.2",
"rxjs": "^7.3.0",
"ts-morph": "^12.0.0",
"typescript": "^4.3.5",
"uuid": "^3.3.2"
},
"devDependencies": {
"#nestjs/testing": "^5.1.0",
"#types/jest": "^23.3.1",
"#types/lodash": "^4.14.134",
"#types/node": "^10.7.1",
"#types/supertest": "^2.0.5",
"jest": "^23.5.0",
"nodemon": "^1.18.3",
"prettier": "^1.14.2",
"supertest": "^3.1.0",
"ts-jest": "^23.1.3",
"ts-loader": "^4.4.2",
"ts-node": "^7.0.1",
"tsconfig-paths": "^3.5.0",
"tslint": "5.11.0"
}
Someone let me know how can I resolve this error.Any help on this will be really appreciated.
I fixed this by updating #types/node to the latest version. This specific error message is then fixed!
I am facing the following error:
'Switch' cannot be used as a JSX component.
Its instance type 'Switch' is not a valid JSX element.
The types returned by 'render()' are incompatible between these types.
Type 'React.ReactNode' is not assignable to type 'import("/usr/src/app/client/node_modules/#types/react-transition-group/node_modules/#types/react/index").ReactNode'.
Type '{}' is not assignable to type 'ReactNode'.
Type '{}' is not assignable to type 'ReactPortal'. TS2786
I have not changed any version. And also not modify the code of my app. 5 days ago this started to not compile in my remote server. I create the images on a alpine:node docker with version 14.17.4
Can someone provide some insight on where is the error here?
Dependencies versions:
"dependencies": {
"#material-ui/core": "^4.11.0",
"#material-ui/icons": "^4.9.1",
"#material-ui/lab": "^4.0.0-alpha.56",
"#material-ui/pickers": "^4.0.0-alpha.12",
"#testing-library/jest-dom": "^4.2.4",
"#testing-library/react": "^9.5.0",
"#testing-library/user-event": "^7.2.1",
"#types/openpgp": "^4.4.14",
"#types/truncate-middle": "^1.0.1",
"axios": "^0.20.0",
"bottleneck": "^2.19.5",
"clsx": "^1.1.1",
"file-saver": "^2.0.5",
"file-selector": "^0.2.2",
"form-data": "^3.0.0",
"formik": "^2.1.4",
"formik-material-ui": "^2.0.0-beta.1",
"formik-material-ui-lab": "0.0.5",
"formik-material-ui-pickers": "0.0.8",
"http-proxy-middleware": "^1.0.6",
"lodash": "^4.17.15",
"material-ui-dropzone": "3.3.0",
"moment": "^2.26.0",
"node-fetch": "^2.6.0",
"node-sass": "^4.14.1",
"openpgp": "^4.4.5",
"promise.allsettled": "^1.0.2",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-flexbox-grid": "^2.1.2",
"react-ga": "^2.7.0",
"react-joyride": "^2.3.0",
"react-kawaii": "^0.16.0",
"react-router-dom": "^5.2.0",
"react-scripts": "3.4.1",
"react-scrollable-feed": "^1.1.2",
"react-snowfall": "1.0.2",
"react-spring": "^8.0.27",
"trace-error": "^1.0.3",
"truncate-middle": "^1.0.6",
"typescript": "^3.7.5",
"uuid": "^8.1.0",
"yup": "^0.29.1"
},
"devDependencies": {
"#types/file-saver": "^2.0.1",
"#types/jest": "^24.9.1",
"#types/lodash": "^4.14.155",
"#types/node": "^12.12.59",
"#types/react": "^16.9.36",
"#types/react-dom": "^16.9.8",
"#types/react-kawaii": "^0.11.0",
"#types/react-router-dom": "^5.1.5",
"#types/uuid": "^8.0.0",
"#types/yup": "^0.29.3"
}
Could it be that the dependencie React version of react-transition-group is different than the normal one? It doesn't make sense for me that this compiles in local and not in remote.
Enviroment
React Native CLI 0.63.2
Windows 10 x64 bit
Node v14.4.0
Packages (package.json):
"dependencies": {
"#fortawesome/fontawesome-svg-core": "^1.2.30",
"#fortawesome/free-solid-svg-icons": "^5.14.0",
"#fortawesome/react-native-fontawesome": "^0.2.5",
"#react-native-community/async-storage": "^1.12.1",
"#react-native-community/blur": "^3.6.0",
"#react-native-community/datetimepicker": "^3.0.4",
"#react-native-community/masked-view": "^0.1.10",
"#react-native-community/netinfo": "^5.9.7",
"#react-native-community/picker": "^1.8.1",
"#react-native-firebase/app": "^8.4.6",
"#react-navigation/native": "^5.7.1",
"#react-navigation/stack": "^5.7.1",
"md5": "^2.3.0",
"moment": "^2.27.0",
"react": "16.13.1",
"react-hook-form": "^6.4.1",
"react-native": "0.63.2",
"react-native-code-push": "^6.3.0",
"react-native-code-push-saga": "^1.0.1",
"react-native-gesture-handler": "^1.8.0",
"react-native-reanimated": "^1.13.1",
"react-native-safe-area-context": "^3.1.7",
"react-native-safe-area-view": "^1.1.1",
"react-native-screens": "^2.9.0",
"react-native-snap-carousel": "^4.0.0-beta.5",
"react-native-svg": "^12.1.0",
"react-native-ui-lib": "^5.15.0",
"react-redux": "^7.2.1",
"redux": "^4.0.5",
"redux-logger": "^3.0.6",
"redux-saga": "^1.1.3"
},
"devDependencies": {
"#babel/core": "7.10.5",
"#babel/runtime": "7.10.5",
"#react-native-community/eslint-config": "1.1.0",
"babel-jest": "25.5.1",
"eslint": "6.8.0",
"jest": "25.5.4",
"metro-react-native-babel-preset": "0.59.0",
"react-native-svg-transformer": "^0.14.3",
"react-test-renderer": "16.13.1"
}
Problem
Whenever I import #react-native-community/netinfo or #react-native-community/async-storage it seems to work fine on Android Emulator. However if I test it live on my iPhone 11 device it crashes almost instantly. All I have to do in order to reproduce the problem is only to import the packages and run it on a iOS device.
I currently don't have the ability to debug for iOS devices as I do not own a MacOS. Is this a known bug or is there a solution to this?
Both packages are from React Native community maybe there is a pattern there. Maybe the packages are affecting other packages causing a crash.
I took over a ASP.net solution with multiple projects in Visual Studio (Professional 2017), one of these projects is in React. I have some experience with React-Native, but I am rather new to React, plus I am new to the code base I inherited.
Since the project was using many outdated and potentially insecure packages (according to npm audit), I decided to update using NPM by carefully replacing some ^1.2.3 with * inside my package.json (see below) as I read somewhere that this is common procedure.
Although there are no errors displayed in Visual Studio's Error List, the React project has troubles to compile and I am seeing an empty page in the browser. The error code is
index.tsx:1 Uncaught Error: Module parse failed: Unexpected token (51:4)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
|
| ReactDOM.render(
> <LocaleProvider locale={enUS}>
| <Provider store={store}>
| <Layout>
at eval (index.tsx:1)
at Object../src/index.tsx (bundle.js:96)
at __webpack_require__ (bundle.js:20)
at bundle.js:84
at bundle.js:87
(anonymous) # index.tsx:1
./src/index.tsx # bundle.js:96
__webpack_require__ # bundle.js:20
(anonymous) # bundle.js:84
(anonymous) # bundle.js:87
This looks like some webpack issue, but the exact error message is changing while I am trying to resolve the dependencies.
More curiously, my IDE is crashing after a few minutes, while contentiously creating files named VMxx, see my screenshot of the solution explorer
Inside those files I find e.g.
window.__REACT_DEVTOOLS_GLOBAL_HOOK__ && window.__REACT_DEVTOOLS_GLOBAL_HOOK__.renderers.size > 0
Clearly, something went wrong with the package update. But what does the described behavior mean? Can I deduce which packages I better should not have updated?
Package.json before
"dependencies": {
"antd": "^2.10.0",
"babel-polyfill": "^6.23.0",
"download": "^6.2.5",
"immutable": "^3.8.1",
"moment": "^2.24.0",
"react": "15.5.3",
"react-dom": "15.5.3",
"react-redux": "^5.0.4",
"react-router-dom": "^4.1.1",
"react-router-redux": "^5.0.0-alpha.6",
"redux": "^3.6.0",
"redux-saga": "^0.14.8",
"reselect": "^3.0.0",
"whatwg-fetch": "^2.0.3"
},
"devDependencies": {
"#types/react": "15.0.21",
"#types/react-dom": "0.14.23",
"#types/react-redux": "^4.4.40",
"#types/react-router-redux": "^5.0.0",
"awesome-typescript-loader": "3.1.2",
"babel-core": "^6.24.1",
"babel-loader": "^7.0.0",
"babel-plugin-transform-es2015-parameters": "^6.24.1",
"babel-preset-env": "^1.4.0",
"css-loader": "^3.2.0",
"extract-text-webpack-plugin": "^2.1.0",
"less": "^2.7.2",
"less-loader": "^4.0.3",
"source-map-loader": "0.2.1",
"style-loader": "^0.17.0",
"ts-loader": "2.0.3",
"typescript": "2.2.1",
"webpack": "^2.7.0"
}
Package.json afterwards
"dependencies": {
"#types/node": "*",
"#types/react-select": "*",
"antd": "2.10.0",
"babel-polyfill": "6.23.0",
"download": "6.2.5",
"draft-js": "^0.11.0",
"immutable": "3.8.2",
"jquery": "^3.4.1",
"moment": "*",
"react": "*",
"react-dom": "*",
"react-lazy-load": "^3.0.13",
"react-redux": "*",
"react-router-dom": "*",
"react-router-redux": "*",
"redux": "3.6.0",
"redux-saga": "0.14.8",
"reselect": "3.0.1",
"webpack-cli": "^3.3.8",
"whatwg-fetch": "^3.0.0"
},
"devDependencies": {
"#types/react": "^16.9.2",
"#types/react-dom": "0.14.23",
"#types/react-redux": "4.4.40",
"#types/react-router-dom": "^4.3.5",
"#types/react-router-redux": "5.0.0",
"ajv": "^6.10.2",
"awesome-typescript-loader": "3.1.2",
"babel-core": "6.26.3",
"babel-loader": "7.1.5",
"babel-plugin-transform-es2015-parameters": "6.24.1",
"babel-preset-env": "1.7.0",
"css-loader": "*",
"less": "2.7.3",
"less-loader": "4.1.0",
"source-map-loader": "0.2.1",
"style-loader": "0.17.0",
"ts-loader": "2.0.3",
"typescript": "2.2.1",
"webpack": "^4.40.2"
}