-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
create-react-app: TypeError: Class constructor [...] cannot be invoked without 'new' #15
Comments
I think there is a relationship with this TSDX PR. But two commits later, the Typescript config override was set back to before the PR. I think |
I'm getting closer to understanding the problem. Here is a quote from @gaeron about this problem:
I think mobx-keystone/packages/lib/src/model/Model.ts Lines 160 to 161 in 1e8e3db
|
It depends actually on the target of the user side transpiled code and the library transpiled code There are two ways to fix it without touching the code
Basically, the user side and library must match (either es5 or es6) Does CRA use the ESM version or the common js one? if so maybe the es version could be defaulted to compile to es6 |
Or maybe it is just the time to ship ES6 by default, but that might keep people with old browsers out :( |
Basically
If the user code is ES6 and the library is ES5 then for a non extended model it will be class -> FC (Model) -> FC (BaseModel) but for extended model it is class -> FC (ExtendedModel) -> class -> FC (Model) -> FC (BaseModel) A solution keeping es5 is possible btw, but it requires proxies :-/ |
With #14 merged, CRA uses the ESM version. Before #14, it was using CommonJS.
Does the following line from TSDX's Rollup config mean that TSDX compiles the library to ES5 because targets: opts.target === 'node' ? { node: '8' } : undefined,
In the example I provided to reproduce this error, I believe Typescript is configured to transpile to ES5, isn't it? "target": "es5", Yet I'm getting the error.
What would need to be changed for this? By the way, since TSDX v0.9.0, TSDX's Rollup config can be customized.
Is my understanding correct that there is no way to support client code for both ES5 and ES6 simultaneously without ES6 Proxy? You're using ES6 Set (e.g. here), so doesn't this require the client target to be ES6 anyway? Or is ES6 Set polyfilled? If there is no way to support ES5 and ES6 client code with the same library, would it make sense to build 2 versions, one for ES5 and one for ES6, and publish them separately? This would be somewhat similar to |
Because CRA ignores that for development mode, if you look at the main.js file generated in dev mode in the chrome inspector you will see this
Either way I think I found a solution with the PR that works for everything :) |
Indeed, thanks a lot, again! :-) |
When using
ExtendedModel
in acreate-react-app
-based app, I'm getting the following error:This is a minimal reproduction: https://github.com/sisp/mobx-keystone-cra-issue/tree/issue-15
The error does not occur when I run the example with
ts-node
, so I think the problem originates from CRA's usage of Babel + Typescript build chain.The text was updated successfully, but these errors were encountered: