Closed
Description
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.14
Then, specify:
- Operating system: MAC OSX
- Browser and version (if relevant): chrome
Steps to Reproduce
- install swagger-codegen and generate javascript project according to some api spec
- install local swagger module according to README.md file in the generated swagger project
- import the module in the react project ant it shows:
Module not found: Can't resolve 'ApiClient' in /path/to/API
Expected Behavior
No error
Actual Behavior
In swagger issue 3537. It discusses this issue and bring 2 solutions:
Disabling directly edit the code source :
// commenting the first IF branch
//if (typeof define === 'function' && define.amd) {
// // AMD. Register as an anonymous module.
// define(['superagent'], factory);
//} else
if (typeof module === 'object' && module.exports) {
// CommonJS-like environments that support module.exports, like Node.
module.exports = factory(require('superagent'));
}
or via Webpack configs:
npm install --save-dev imports-loader
// and then add this loader to the webpack configs
{ test: /\.js/, loader: 'imports?define=>false'}
Since, it is not advised to revise the react-scripts, could create-react-app support swagger client imports?
Metadata
Metadata
Assignees
Labels
No labels