mocha not recognizing structuredClone is not defined - node.js

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))

Related

Getting mongoose error on building NestJs project

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!

React application rendering in local but build fails on remote

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.

Integrat #chilkat/ck-electron16-win-ia32 in electron project

Actualy I try to intgrat
but I face to this exception my node version is 16.3.2 32bit
C:\Users\PC\Desktop\electron_project_X32\node_modules\express\lib\application.js:630 Error: Loading non-context-aware native module in renderer: '\\?\C:\Users\PC\Desktop\electron_project_X32\node_modules\#chilkat\ck-electron16-win-ia32\chilkat.node'. See https://github.com/electron/electron/issues/18397.
at process.func [as dlopen] (node:electron/js2c/asar_bundle:5)
and this is may package.json
"devDependencies": {
"cpx": "^1.5.0",
"electron": "^16.1.0",
"electron-packager": "^15.4.0",
"electron-rebuild": "^3.2.7",
"ncp": "^2.0.0"
},
"dependencies": {
"#chilkat/ck-electron16-win-ia32": "^9.50.89",
"#chilkat/ck-node16-win-ia32": "^9.50.89",
"cors": "^2.8.5",
"crypto-js": "^4.1.1",
"crypto-md5": "^1.0.0",
"dotenv": "^16.0.0",
"electron-tabs": "^0.15.0",
"express": "^4.17.3",
"ffi-napi": "^4.0.3",
"freemarker": "^2.0.1",
"md5": "^2.3.0",
"multer": "^1.4.4",
"node-cron": "^3.0.0",
"node-key-sender": "^1.0.11",
"node-notifier": "^10.0.1",
"npm": "^8.5.3",
"pkg": "^5.5.2",
"serialport": "^10.4.0",
"sudo-prompt": "^9.2.1",
"through2": "^4.0.2",
"websocket": "^1.0.34"
}
I try to set this app.allowRendererProcessReuse = false in main.js but it don't solve the problem
SOLVED BY #chilkat Software by upgrading the current version of chilkat/ck-electron16-win64  and win32

Azure NodeJS Web Service exists with status code null and signal SIGSEGV

I'm trying to deploy a NodeJS application to an Azure web service (Node version 10.14, Azure B1 plan), however, when I run the application, it always exists with status null and signal SIGSEGV.
There were no errors outputted. I tried deploying the same code to Heroku and there were no issues at all.
I tried using the segfault-handler module in hopes that it will tell what is wrong, but the only thing that it logs is:
PID 147 received SIGSEGV for address: 0x2c26
Any ideas what might cause this? One thing I was able to find that it might be related to native modules, but I still don't know which one might cause this.
EDIT
The Azure web service uses Linux OS and not Windows.
Modules used:
"dependencies": {
"apidoc": "^0.17.7",
"applicationinsights": "^1.3.1",
"bcrypt": "^3.0.5",
"chalk": "^2.4.2",
"concurrently": "^3.6.1",
"dotenv": "^6.2.0",
"excel4node": "^1.7.1",
"express": "^4.17.1",
"express-sslify": "^1.2.0",
"firebase-admin": "^7.2.0",
"get-port": "^4.2.0",
"is-json": "^2.0.1",
"joi": "^14.3.1",
"jsonwebtoken": "^8.5.1",
"lodash": "^4.17.11",
"mailgun-js": "^0.22.0",
"mkdirp": "^0.5.1",
"moment": "^2.24.0",
"morgan": "^1.9.1",
"node-cache": "^4.2.0",
"node-cleanup": "^2.1.2",
"node-schedule": "^1.3.1",
"nodemon": "^1.19.0",
"number-to-words": "^1.2.4",
"pdf-to-base64": "^1.0.2",
"pdfkit": "^0.9.1",
"pg": "^7.9.0",
"pug": "^2.0.3",
"rate-limiter-flexible": "^1.0.2",
"request": "^2.88.0",
"request-promise-native": "^1.0.7",
"segfault-handler": "^1.2.0",
"sequelize": "^5.8.7",
"socketcluster": "^14.3.3",
"socketcluster-client": "^14.2.2",
"socketcluster-server": "^14.4.0",
"systeminformation": "^4.0.15",
"twilio": "^3.30.0",
"umzug": "^2.2.0",
"uuid": "^3.3.2"
},
"devDependencies": {
"#types/chai": "^4.1.7",
"#types/chalk": "^2.2.0",
"#types/cookie-parser": "^1.4.1",
"#types/dotenv": "^6.1.0",
"#types/express": "^4.16.0",
"#types/joi": "^14.3.3",
"#types/lodash": "^4.14.107",
"#types/mocha": "^5.2.6",
"#types/moment": "^2.13.0",
"#types/morgan": "^1.7.35",
"#types/node": "^9.6.5",
"#types/request-promise": "^4.1.42",
"#types/serialize-javascript": "^1.3.2",
"#types/sinon": "^7.0.11",
"#types/uuid": "^3.4.3",
"casual": "^1.6.0",
"chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
"mocha": "^5.2.0",
"sinon": "^7.2.3"
}
As you said, if there are few node modules related to native apis like Win32k.sys, it will be terminated immediately by Azure Web App sandbox once run.
Therefore, the possible reason may be these limits and restrictions described in sandbox secure environment, such as below.
Please inspect your used modules carefully. Hope it helps.

After installing graphql-tools and graphql-express. Error message in console 'Cannot find name 'AsyncIterator'

Error Log On initiating application
While initiating the application it shows the following error and i tried couple of fixes from online which has mentioned below but none of them has worked requesting for suggestions and solutions
node_modules/#types/graphql/subscription/subscribe.d.ts(17,12): error TS2304: Cannot find name 'AsyncIterator'.
node_modules/#types/graphql/subscription/subscribe.d.ts(29,12): error TS2304: Cannot find name 'AsyncIterable'.
node_modules/graphql-tools/dist/stitching/makeRemoteExecutableSchema.d.ts(3,109): error TS2304: Cannot find name 'AsyncIterator'.
Fixes Tried as per google results
Adding esnext.asynciterable to the tsconfig.json
Adding esnext to the tsconfig.json
But none of them has worked.
package.json
"dependencies": {
"async": "^2.6.0",
"body-parser": "^1.18.2",
"cookie-parser": "^1.4.3",
"cors": "^2.8.4",
"ejs": "^2.5.7",
"errorhandler": "^1.5.0",
"express": "^4.16.2",
"express-graphql": "^0.6.12",
"graphql": "^0.13.2",
"graphql-tools": "^3.1.1",
"ldapjs": "^1.0.1",
"method-override": "^2.3.10",
"moment": "^2.20.1",
"mongoose": "^4.13.6",
"morgan": "^1.9.0",
"mysql": "^2.15.0",
"node-schedule": "^1.3.0",
"nodemiral": "^1.1.1",
"pug": "^2.0.0-rc.4",
"q": "^1.5.1",
"request": "^2.85.0",
"sendmail": "^1.2.0",
"serve-favicon": "^2.4.5",
"socket.io": "^2.0.4",
"ts-node": "^3.3.0"
},
"devDependencies": {
"#types/async": "^2.0.47",
"#types/body-parser": "^1.16.8",
"#types/chai": "^4.0.8",
"#types/chai-http": "^3.0.3",
"#types/cookie-parser": "^1.4.1",
"#types/cors": "^2.8.3",
"#types/errorhandler": "0.0.32",
"#types/ldapjs": "^1.0.3",
"#types/lodash": "^4.14.106",
"#types/method-override": "0.0.31",
"#types/mocha": "^2.2.44",
"#types/mongodb": "^2.2.16",
"#types/mongoose": "^4.7.28",
"#types/morgan": "^1.7.35",
"#types/mysql": "^2.15.3",
"#types/node-schedule": "^1.2.2",
"#types/request": "^2.47.0",
"#types/serve-favicon": "^2.2.30",
"#types/socket.io": "^1.4.32",
"chai": "^4.1.2",
"chai-http": "^3.0.0",
"grunt": "^1.0.1",
"grunt-concurrent": "^2.3.1",
"grunt-contrib-copy": "^1.0.0",
"grunt-contrib-watch": "^1.0.0",
"grunt-mocha-test": "^0.13.3",
"grunt-newer": "^1.3.0",
"grunt-nodemon": "^0.4.2",
"grunt-ts": "^6.0.0-beta.17",
"grunt-tslint": "^5.0.1",
"grunt-typedoc": "^0.2.4",
"mocha": "^4.0.1",
"mocha-typescript": "^1.1.12",
"nodemon": "^1.12.4",
"tslint": "^5.8.0",
"typescript": "^2.6.2"
}
Delete node modules then:-
npm install
npm install --save graphql-subscriptions
npm install --save #types/graphql
npm install --save #types/ws
add the following in tsconfig.json
"compilerOptions": {
"lib": [
"esnext.asynciterable"
]
I encountered the same problem and adding
"lib": ["es2017", "esnext", "esnext.asynciterable"]
to my tsconfig.json did not help, which was frustrating.
I went through lots of suggestions and eventually the answer by Shivendra solved it for me. Hope this will help others coming here in the future.

Resources