aerogear / uniforms-patternfly

Uniforms patternfly
Apache License 2.0
13 stars 10 forks source link

TypeError: Class constructor AutoForm cannot be invoked without 'new' #103

Open rafaeltuelho opened 2 years ago

rafaeltuelho commented 2 years ago

my project dependencies are:

  "dependencies": {
    "@patternfly/react-core": "^4.162.3",
    "@patternfly/react-icons": "^4.13.1",
    "@patternfly/react-styles": "^4.12.5",
    "ajv": "^8.8.2",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "simpl-schema": "^1.12.0",
    "uniforms": "^3.7.0",
    "uniforms-bridge-json-schema": "^3.7.0",
    "uniforms-bridge-simple-schema-2": "^3.7.0",
    "uniforms-patternfly": "^4.7.4"
  }

and I'm getting the following error when using AutoForm from uniforms-patternfly

Uncaught TypeError: Class constructor AutoForm cannot be invoked without 'new'
    at new _ (webpack-internal:///./node_modules/uniforms-patternfly/dist/esm/AutoForm.js:15)
    at constructClassInstance (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:12716)
    at updateClassComponent (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:17425)
    at beginWork (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:19073)
    at HTMLUnknownElement.callCallback (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:3945)
    at Object.invokeGuardedCallbackDev (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:3994)
    at invokeGuardedCallback (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:4056)
    at beginWork$1 (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:23959)
    at performUnitOfWork (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:22771)
    at workLoopSync (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:22702)
rafaeltuelho commented 2 years ago

found this old issue on uniforms projects repo but it was related to metor. Not sure if it applies to patternfly and/or aerogear: https://github.com/vazco/uniforms/issues/433

riccardo-forina commented 2 years ago

This happened to me often in the past, it's likely caused by multiple versions of uniforms in your project. You can check it using nvm ls uniforms or yarn why uniforms.

If you have multiple versions of it, you should try to pin the dependencies so as to have all the versions aligned. I rarely managed to fix the problem this way, but it might help you.

tarilabs commented 2 years ago

I had the same issue as @rafaeltuelho

I did not have multiple versions of uniforms:

$ npm ls uniforms
patternfly-seed@0.0.2 /Users/mmortari/git/... .../demogui
├─┬ uniforms-bridge-json-schema@3.7.0
│ └── uniforms@3.7.0 deduped
├─┬ uniforms-patternfly@4.7.4
│ └── uniforms@3.7.0 deduped
├─┬ uniforms-unstyled@3.7.0
│ └── uniforms@3.7.0 deduped
└── uniforms@3.7.0

It seems to me instead using import as:

import { AutoForm } from "uniforms-patternfly/dist/es6";

solved the Class constructor AutoForm cannot be invoked without 'new' problem for me.

rafaeltuelho commented 2 years ago

Thanks for pointing this out @tarilabs . Will give it a try.