Skip to content
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

React Native TypeError Object is not a function #1397

Open
npalethorpe opened this issue Oct 18, 2018 · 11 comments
Open

React Native TypeError Object is not a function #1397

npalethorpe opened this issue Oct 18, 2018 · 11 comments

Comments

@npalethorpe
Copy link

@npalethorpe npalethorpe commented Oct 18, 2018

Q&A (please complete the following information)

  • OS: macOS
  • Environment: React Native
  • Method of installation: npm
  • Swagger-Client version: 3.8.21
  • Swagger/OpenAPI version: [e.g. Swagger 2.0, OpenAPI 3.0]

Weird exception within a React Native project (iOS) - Everything runs fine in debug mode, however when I flick over to Release mode on iOS I get the following error:

TypeError: e is not a function. (in 'e({url:t,loadSpec:!0,requestInterceptor:r,responseInterceptor:n,headers:{Accept:"application/json"},credentials:a}}','e' is an instance of Object)

As this has been minified I stopped the minification and got the following: "TypeError: Object is not a function (near '...e...')".

Below is a summed up version of my code, however it isn't reaching the stage of actually attempting to make a call so I'm not sure its much use - and just to emphasise on the point; this works 100% in debug mode.

import Swagger from 'swagger-client';

Swagger({
    url: SWAGGER_URL,
    requestInterceptor: function (req) {
        req.headers.appVersion = 1;
        req.headers.authorization = USER_AUTH_TOKEN;
    },
    responseInterceptor: function (res){
    }
 }).then((client) => {
    resolve(client);
}).catch((err) => {
    reject(err);
});
@npalethorpe

This comment has been minimized.

Copy link
Author

@npalethorpe npalethorpe commented Oct 18, 2018

I managed to resolve this issue by doing a download of the project and including it as a local npm package. The only thing I had to change was that Package.json in the npm project had...
"main": "dist/index.js"
which I had to change to...
"main": "src/index.js".

@marcosmartinez7

This comment has been minimized.

Copy link

@marcosmartinez7 marcosmartinez7 commented Oct 25, 2018

Exactly the same problem, also with the assembleDebug.

React Native. 57.3

Any ideas of why this could be happening?

The @npalethorpe solution does the trick.

@shockey

This comment has been minimized.

Copy link
Member

@shockey shockey commented Oct 29, 2018

@npalethorpe, what do you see fi you do this:

import Swagger from 'swagger-client';

console.log(Swagger)
@shockey

This comment has been minimized.

Copy link
Member

@shockey shockey commented Oct 29, 2018

(If anyone else can do this, it would be helpful to see your output as well)

@joh-klein

This comment has been minimized.

Copy link

@joh-klein joh-klein commented Nov 23, 2018

with v3.8.22 the output is (and it still doesn't work):

function s(t){var n=this,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if("string"==typeof t?o.url=t:o=t,!(this instanceof s))return new s(o);(0,c.default)(this,o);var u=this.resolve().then(function(){return n.disableInterfaces||(0,c.default)(n,s.makeApisTagOperation(n)),n});return u.client=this,u}

And the working output (thx to @npalethorpe):

function I(t){var s=this,l=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(\'string\'==typeof t?l.url=t:l=t,!(this instanceof I))return new I(l);(0,u.default)(this,l);var o=this.resolve().then(function(){return s.disableInterfaces||(0,u.default)(s,I.makeApisTagOperation(s)),s});return o.client=this,o}

Looking at it closely the only difference seems to be "string" vs \'string\'

@joh-klein

This comment has been minimized.

Copy link

@joh-klein joh-klein commented Dec 4, 2018

What I did to get my react-native project to work again: I took the un-minified output from npm run build:umd:dev and replaced everything in dist/index.js with it. This can be done with https://www.npmjs.com/package/patch-package in an orderly fashion and without to much hassle in a CI/CD workflow.

I also tried to upgrade swagger-client to webpack 4. It looked promising, but I didn't have the time to continue investigating.

@devth

This comment has been minimized.

Copy link

@devth devth commented Dec 12, 2018

This is breaking me too. Kind of a nasty bug since it only shows up in production.

@devth

This comment has been minimized.

Copy link

@devth devth commented Jan 5, 2019

Possible to fix for the next release?

@shockey

This comment has been minimized.

Copy link
Member

@shockey shockey commented Jan 15, 2019

@devth I can't give a specific date for a fix, but this is on our radar and will be worked on soon!

@shortcarver

This comment has been minimized.

Copy link

@shortcarver shortcarver commented Jan 16, 2019

FWIW, I started working back through the versions, and this appears to have been introduced in v3.6.0.
v3.5.2 works for me.

@ronoyama7

This comment has been minimized.

Copy link

@ronoyama7 ronoyama7 commented Jun 15, 2019

New version (v3.9.0) does not work too. it does not work only in production.
Any solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
7 participants
You can’t perform that action at this time.