vazco / uniforms

A React library for building forms from any schema.
https://uniforms.tools
MIT License
1.96k stars 245 forks source link

Update 3.5.1 -> 3.5.2 breaks meteor package with customized uniforms-unstyled #1001

Closed JanMP closed 3 years ago

JanMP commented 3 years ago

After updating I get the same error as #703

Uncaught TypeError: Class constructor _ cannot be invoked without 'new'
    at new AutoForm
    at new _ (AutoForm.tsx:6)

I only changed some of the fields. AutoForm is untouched. Renaming _ to something else did not help.

Repro is here: https://github.com/JanMP/repro-uniforms-3.5.2-error (see two commits for changes that lead to problem)

radekmie commented 3 years ago

Hi @JanMP. Please do check whether the newest version works. I guess this problem got fixed in v3.5.4 (actually v3.5.3, but it's an incorrect release).

JanMP commented 3 years ago

No, it doesn't. I updated from 3.5.1. to 3.5.5. Things broke and then I went back and forth and narrowed it down to starting at 3.5.2

radekmie commented 3 years ago

OK, it makes sense. We'll look into that soon.

kestarumper commented 3 years ago

Hi @JanMP, thanks for pointing this out as it appears that we've introduced a regression. We're investigating and we'll keep you posted once we find something.

radekmie commented 3 years ago

I thought about it a little bit more and I'd say that we have to decide, whether we publish actual ES6 classes or not. Overall, there's no point in es5/es6 builds and we should rather have a cjs/esm separation, just like other packages. The only question is what EcmaScript standard are we going to use for the build.

ES6 seems a valid choice, as it's already supported by all supported platforms. And if someone's bundler is down-leveling classes, then it's up to the user to downlevel them in our bundle as well.

What do you think?


@kestarumper In order to make sure that it'll work without problems in all major platforms, i.e., CRA, Gatsby, Meteor, please od check whether the es6 build works in all of them. If it does, then I think we have our winner here.

macrozone commented 3 years ago

just to add some information: 3.5.2 also breaks in nextjs (tried actually with 3.5.5). 3.5.1 works though

radekmie commented 3 years ago

@kestarumper Could you post your status here? I know you've checked something already.

kestarumper commented 3 years ago

A few facts from my side.

uniforms 3.5.5

create-react-app

{
  "compilerOptions": {
    "target": "es5",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noFallthroughCasesInSwitch": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react-jsx"
  },
  "include": [
    "src"
  ]
}

gatsby

tsconfig ```json { "compilerOptions": { "outDir": "./dist/", "sourceMap": true, "noImplicitAny": true, "module": "commonjs", "target": "esnext", "jsx": "react", "lib": ["dom", "es2015", "es2017"] }, "include": [ "./src/**/*" ] } ```

Right now I'm performing further tests on what might be the issue, and I'm trying to find a common solution.

[UPDATE]

I artificially forced your reproduction to use uniforms/es6 and it works correctly. I also checked create-react-app and gatsby if they work correctly, and I managed to make all three work (no application code changes) with the

// node_modules/uniforms/package.json
...
"main": "./es5/index.js",
"module": "./es6/index.js",
...

I'll probably also try Next.js and if it will work then I'll create a PR to set those main and module to es5 and es6 builds.

[UPDATE 2]

In the end, we created two builds targeting ES6 with CommonJS modules and ES6 modules. More on that in #1028.

JanMP commented 2 years ago

With Meteor 2.5.2 and Uniforms 3.7.0 everything works fine in the browser, but I get the error with Cordova (output from ios, android does not work either).

2022-01-03 11:55:29.911453+0100 sdui-dev[11709:11582136] Uncaught Error: TypeError: Cannot call a class constructor without |new|:79731:http://localhost:12400/__cordova/packages/modules.js?hash=9e468c6d60c3f11da1c3669c0b0c444db669c463
2022-01-03 11:55:29.912947+0100 sdui-dev[11709:11582136] ERROR: The above error occurred in the <AutoValidatedQuickUnstyledForm> component:
    in AutoValidatedQuickUnstyledForm (created by FormTest)
    in div (created by FormTest)
radekmie commented 2 years ago

Hi @JanMP, sorry for the late response. As we're not using Codova ourselves anymore, we'd need a reproduction to confirm and fix that. Please do file a new issue with a reproduction.