auth0 / node-jws

JSON Web Signatures
http://self-issued.info/docs/draft-ietf-jose-json-web-signature.html
MIT License
711 stars 107 forks source link

Object prototype may only be an Object or null: undefined #109

Open ningji opened 1 year ago

ningji commented 1 year ago

When migrating my app from react 17 to 18, got this in chrome when starting my app.

Uncaught runtime errors: × ERROR Object prototype may only be an Object or null: undefined TypeError: Object prototype may only be an Object or null: undefined at Function.create () at Object.inherits (http://localhost:3010/static/js/bundle.js:62529:31) at ./node_modules/jws/lib/data-stream.js (http://localhost:3010/static/js/bundle.js:66271:6) at options.factory (http://localhost:3010/static/js/bundle.js:230212:31) at webpack_require__ (http://localhost:3010/static/js/bundle.js:229657:33) at fn (http://localhost:3010/static/js/bundle.js:229869:21) at ./node_modules/jws/lib/sign-stream.js (http://localhost:3010/static/js/bundle.js:66295:18) at options.factory (http://localhost:3010/static/js/bundle.js:230212:31) at webpack_require__ (http://localhost:3010/static/js/bundle.js:229657:33) at fn (http://localhost:3010/static/js/bundle.js:229869:21)

There're plenty of changes i made to migrate to react 18, so not very sure which one caused the issue. I'll update more info if i find out more, but this is the most of the package.json (except our internal libs). Any help appreciated.

  "scripts": {
    "start": "chmod +x ./env.sh && ./env.sh && mv env-config.js ./public/ && PORT=3010 react-app-rewired start",
    "build": "react-app-rewired build",
    "test": "CI=true react-app-rewired test --reporters=default --reporters=jest-junit --testResultsProcessor=jest-sonar-reporter",
    "test:watch": "react-app-rewired test",
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "lint-staged": {
    "*.{html,js,json,jsx,md,sass,scss,yaml,yml}": [
      "npx prettier --write ."
    ],
    "*.{js,jsx}": [
      "npx eslint --fix ."
    ]
  },
  "dependencies": {
    "framer-motion": "10.16.2",
    "jsonwebtoken": "9.0.2",
    "moment": "^2.29.4",
    "moment-timezone": "^0.5.43",
    "react": "18.2.0",
    "react-dom": "18.2.0",
    "react-router-dom": "6.15.0",
    "react-scripts": "5.0.1",
    "react-toastify": "8.2.0",
    "sass": "1.66.1",
    "web-vitals": "3.4.0"
  },
  "devDependencies": {
    "@testing-library/jest-dom": "6.1.2",
    "@testing-library/react": "14.0.0",
    "@testing-library/user-event": "14.4.3",
    "buffer": "^6.0.3",
    "husky": "8.0.3",
    "jest-junit": "16.0.0",
    "jest-sonar-reporter": "2.0.0",
    "lint-staged": "14.0.1",
    "prettier": "3.0.3",
    "process": "^0.11.10",
    "react-app-rewired": "^2.2.1",
    "util": "^0.12.5"
  }
}
ningji commented 1 year ago

yarn 1.22.19 node 16.16.0 MacOS Ventura

b-smets commented 9 months ago

Running into the same issue. Is there any update on this or how to mitigate this?

FritjofH commented 9 months ago

@b-smets I just got this as well after an npm install. Timing-wise it feels as if we have some library which have upgraded it's dependency hitting a dormant bug here?

b-smets commented 9 months ago

I did some more digging and I think this is caused by Vite externalising stream which causes DataStream to become a Proxy with an undefined prototype. Probably it will work when polyfilling stream in the browser.

b-smets commented 9 months ago

Can confirm that running with the https://www.npmjs.com/package/vite-plugin-node-polyfills plugin, the issue no longer occurs. I suppose the same can be done for other bundlers if required.

This doesn't seem to be an issue with node-jws itself.

FritjofH commented 9 months ago

Thanks for the hint!

I'm using webpack 5 through create-react-scripts with react-app-rewired. Adding the stream polyfill did the resolve the issue for me.

dben89x commented 4 days ago

I ran into this issue, and it resolved itself when I removed jsonwebtoken. Not sure yet how to actually fix it, but hopefully that's a hint.