1

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"
      }
Dan
  • 59
  • 1
  • 6

1 Answers1

0

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