swagger-api / swagger-codegen

swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
http://swagger.io
Apache License 2.0
16.99k stars 6.03k forks source link

Using javascript generated package with React result in error during react build #10451

Open jpiat opened 4 years ago

jpiat commented 4 years ago
Description

I am trying to use a javascript package, generated through swagger editor, in a react application and i get the following error :

"Cannot find module: 'ApiClient'. Make sure this package is installed."

the error is generated when react builds the sr/index.js file of the package.

the package works fine when used with browserify.

Swagger-codegen version

The version used is the one used by swagger-editor latest release : 2.4.15

Swagger declaration file content or url

The yaml content does not trigger a code generation error. Only the generated code does not seem to be compatible with react

Command line used for generation

Generated through swagger-editor

Steps to reproduce

Generate any package and try to bundle in a react aplpication

Related issues/PRs
Suggest a fix/enhancement
jpiat commented 4 years ago

Found a quick/dirty fix. Once the package is generated, use the following on-liner in the package folder

find ./src -type f -name *.js -exec sed -i "s/define.amd/false/g" {} \;

this will disable the if statement that causes the issue.