-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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
Support swagger module with AMD imports? #3247
Comments
Sorry, we don't intend to support AMD. It's time the ecosystem moves forward from a format that isn't used by any system (neither Node nor browsers) and only exists as a legacy. |
@gaearon Sorry for rehashing the past here, but it seems like the logical thread to pull with regards to this topic. While I absolutely agree with your statement above about not supporting AMD, my issue is centered around Swagger's ES6 generated output (specifically the usage of static class properties) and CRA's usage of related polyfills. Following the TC39 rabbit hole reveals:
However, the CRA README says:
Maybe I'm just overly concerned with the semantics, but the CRA README would lead me to believe that Swagger's usage of static class properties should play nicely with CRA, but my terminal says otherwise. At the same time, however, CRA not supporting an early Stage 2 proposal also seems to make sense. So, really, this is just a long-winded way of saying "I'm confused." FWIW, you're obviously not responsible for Swagger's implementation. Given the incredible usefulness and popularity of both Swagger and React, having them live in harmony makes for a killer development setup. |
Facing the same issue as the OP here. Now, the original title of this issue is incorrect. Swagger's generated .js files does not require AMD modules support. It autodetect the proper modules semantics using a cascade of if statements. Now the problem is that by default, webpack loaders give hints that AMD modules are supported, though they are not really. Not sure about the details here, but in the end, since the generated code checks for AMD support before anything else, and is misled to believe that AMD is supported, then it initialize itself incorrectly. The proposed fix is to tell webpack's module loader to completely disable support for AMD modules, by passing the argument
This change seems to me as being compatible with CRA's policy regarding AMD modules... Could it be considered? |
Is there a simpler way to disable AMD support that doesn’t involve adding a loader? If not maybe you could propose this to webpack? |
I could be wrong on that point, but from my understanding, the proposed configuration does not actually add the module, but only declares it explicitly with some parameter. I believe Webpack registers that same module implicitly if it is not declared. Now about having a simpler way to disable AMD support... One way or another, that would still involve modifying the webpack configuration file, which, as of now, implies either ejecting from CRA or cloning the CRA script project... |
No, I’m suggesting that you propose this feature to webpack, and if webpack implements such an option, we’ll enable it by default in CRA. No ejecting. |
@gaearon Webpack implemented this feature: https://webpack.js.org/configuration/module/#rule-parser module: {
rules: [
{
parser: {
amd: false
}
}
]
} @mjameswh you can generate ES6 javascript using swagger, set in config: https://generator.swagger.io/api/gen/clients/javascript {
useES6: true
} |
Disable AMD and solve swagger client issues since there is no intention of supporting it: facebook#3247 (comment)
Using the Which is odd because I know CRA supports that transform [
require("@babel/plugin-proposal-class-properties").default,
{
loose: true,
},
], |
I am using swagger-codegen to generate swagger js client. However, it is hard to import the client module.
Environment
node -v
: 8.1.4npm -v
: 5.4.2yarn --version
(if you use Yarn): 1.1.0npm ls react-scripts
(if you haven’t ejected): 1.0.14Then, specify:
Steps to Reproduce
Expected Behavior
No error
Actual Behavior
In swagger issue 3537. It discusses this issue and bring 2 solutions:
Disabling directly edit the code source :
or via Webpack configs:
Since, it is not advised to revise the react-scripts, could create-react-app support swagger client imports?
The text was updated successfully, but these errors were encountered: