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

Self is not defined #3291

Closed
jd-carroll opened this issue Jun 24, 2017 · 10 comments
Closed

Self is not defined #3291

jd-carroll opened this issue Jun 24, 2017 · 10 comments

Comments

@jd-carroll
Copy link

jd-carroll commented Jun 24, 2017

  • node version
$ node --version
v6.9.5
  • swagger-ui version
"swagger-ui-dist": "^3.0.17",
  • a swagger file reproducing the issue
npm install --save swagger-ui-dist

Sample file:

const express = require('express');
const app = express();
app.listen();
const swaggerDist = require('swagger-ui-dist');
const swaggerUiAssetPath = swaggerDist.getAbsoluteFSPath(); // <-- errors out
app.use('/swagger', express.static(swaggerUiAssetPath));

Full stack trace:

ReferenceError: self is not defined
    at Object.<anonymous> (c:\dev\cpt\ads\ads-web-services\node_modules\swagger-ui-dist\swagger-ui-bundle.js:73:22556)
    at t (c:\dev\cpt\ads\ads-web-services\node_modules\swagger-ui-dist\swagger-ui-bundle.js:1:402)
    at Object.e.exports.e.__esModule.default (c:\dev\cpt\ads\ads-web-services\node_modules\swagger-ui-dist\swagger-ui-bundle.js:72:10755)
    at t (c:\dev\cpt\ads\ads-web-services\node_modules\swagger-ui-dist\swagger-ui-bundle.js:72:110)
    at Object.<anonymous> (c:\dev\cpt\ads\ads-web-services\node_modules\swagger-ui-dist\swagger-ui-bundle.js:72:9958)
    at t (c:\dev\cpt\ads\ads-web-services\node_modules\swagger-ui-dist\swagger-ui-bundle.js:72:110)
    at Object.e.exports.e.__esModule.default (c:\dev\cpt\ads\ads-web-services\node_modules\swagger-ui-dist\swagger-ui-bundle.js:72:11205)
    at t (c:\dev\cpt\ads\ads-web-services\node_modules\swagger-ui-dist\swagger-ui-bundle.js:72:110)
    at Object.<anonymous> (c:\dev\cpt\ads\ads-web-services\node_modules\swagger-ui-dist\swagger-ui-bundle.js:73:1750)
    at t (c:\dev\cpt\ads\ads-web-services\node_modules\swagger-ui-dist\swagger-ui-bundle.js:72:110)
    at c:\dev\cpt\ads\ads-web-services\node_modules\swagger-ui-dist\swagger-ui-bundle.js:72:493
    at Object.<anonymous> (c:\dev\cpt\ads\ads-web-services\node_modules\swagger-ui-dist\swagger-ui-bundle.js:72:503)
    at t (c:\dev\cpt\ads\ads-web-services\node_modules\swagger-ui-dist\swagger-ui-bundle.js:1:402)
    at Object.e.exports.n.(anonymous function).i (c:\dev\cpt\ads\ads-web-services\node_modules\swagger-ui-dist\swagger-ui-bundle.js:71:31725)
    at t (c:\dev\cpt\ads\ads-web-services\node_modules\swagger-ui-dist\swagger-ui-bundle.js:1:402)
    at Object.t (c:\dev\cpt\ads\ads-web-services\node_modules\swagger-ui-dist\swagger-ui-bundle.js:39:4816)
    at t (c:\dev\cpt\ads\ads-web-services\node_modules\swagger-ui-dist\swagger-ui-bundle.js:1:402)
    at Object.t (c:\dev\cpt\ads\ads-web-services\node_modules\swagger-ui-dist\swagger-ui-bundle.js:39:3431)
    at t (c:\dev\cpt\ads\ads-web-services\node_modules\swagger-ui-dist\swagger-ui-bundle.js:1:402)
    at Object.<anonymous> (c:\dev\cpt\ads\ads-web-services\node_modules\swagger-ui-dist\swagger-ui-bundle.js:1:15146)
    at t (c:\dev\cpt\ads\ads-web-services\node_modules\swagger-ui-dist\swagger-ui-bundle.js:1:402)
    at Object.<anonymous> (c:\dev\cpt\ads\ads-web-services\node_modules\swagger-ui-dist\swagger-ui-bundle.js:1:802)
@shockey
Copy link
Contributor

shockey commented Jun 26, 2017

I'm able to reproduce this - thanks for reporting!

@shockey
Copy link
Contributor

shockey commented Jun 26, 2017

The problem here is that we're importing the bundle and Standalone preset in the main file for the module.

This is great for people using swagger-ui-dist in a webapp (see #3126), but isn't getting along well with Node.

We can't remove the references, because that would be a breaking change - we'd have to bump the major version for swagger-ui-dist, which is not acceptable because we want to track swagger-ui's version. It would also completely drop a community-contributed feature, which isn't great.

It may be possible to detect at runtime what context we're running in. I'm going to try out some solutions and try to get this fixed by Friday.

To all - comments and PRs around this are welcome.

@shockey shockey added the Ready label Jun 27, 2017
@goinggood
Copy link

\swagger-api-doc\swagger-ui-bundle.js:73
j.default)("JSONRefError",function(e,t,n){this.originalError=n,(0,T.default)(this,t||{})}),L={},z=new C.default,q={key:"$ref",plugin:function(e,t,n,r){var u=n.slice(0,-1),c=r.getContext(n).baseDoc;if("string"!=typeof e)return new B("$ref: must be a string (JSON-Ref)",{$ref:e,baseDoc:c,fullPath:n});var l=a(e),p=l[0],h=l[1]||"",d=void 0;try{d=c||p?i(p,c):null}catch(t){return o(t,{pointer:h,$ref:e,basePath:d,fullPath:n})}var m=void 0,v=void 0;if(!y(h,d,u,r)){if(null==d?(v=f(h),void 0===(m=r.get(v))&&(m=new B("Could not resolve reference: "+e,{pointer:h,$ref:e,baseDoc:c,fullPath:n}))):(m=s(d,h),m=null!=m.__value?m.__value:m.catch(function(t){throw o(t,{pointer:h,$ref:e,baseDoc:c,fullPath:n})})),m instanceof Error)return[N.default.remove(n),m];var =N.default.replace(u,m,{$$ref:e});return d&&d!==c?[,N.default.context(u,{baseDoc:d})]:g(r.state,)?void 0:}}},U=(0,T.default)(q,{docCache:L,absoluteify:i,clearCache:u,JSONRefError:B,wrapError:o,getDoc:c,spl

ReferenceError: self is not defined

We are facing this issue with swagger api.
Appreciate the early solution to this issue.

@homerjam
Copy link

homerjam commented Jul 4, 2017

+1

@shockey
Copy link
Contributor

shockey commented Jul 4, 2017

This should be fixed next time the projects are released - I wrapped the require calls for the SwaggerUIBundle and SwaggerUIStandalonePreset in a try/catch in #3336, which should keep the whole module from exploding when that happens in a Node context.

I'll close this issue once the projects are released with a fix - once that's done, I invite everyone that has commented to update whether the issue is resolved from your end.

edited: s/if/whether

@shockey
Copy link
Contributor

shockey commented Jul 8, 2017

Releasing now, so this fix should be live shortly.

@shockey shockey closed this as completed Jul 8, 2017
@chaitralisk
Copy link

Hi
I am working on swagger-ui. But I am getting this issue::
swagger-ui-standalone-preset.js:2 Uncaught SyntaxError: Unexpected token <
(index):76 Uncaught ReferenceError: SwaggerUIBundle is not defined
at window.onload ((index):76)

@shockey
Copy link
Contributor

shockey commented Jul 10, 2017

@chaitralisk, are you sure you're loading swagger-ui-bundle.js into your page? I get a similar error if I comment out this line.

@chaitralisk
Copy link

Yes, I am loadingswagger-ui-bundle.js into page.I have created nodejs server which will load index.html file.
But I am getting:
swagger-ui-standalone-preset.js:2 Uncaught SyntaxError: Unexpected token <
(index):76 Uncaught ReferenceError: SwaggerUIBundle is not defined
at window.onload ((index):76)

@shockey
Copy link
Contributor

shockey commented Jul 12, 2017

@chaitralisk, can you please open a new ticket so we can help you with this? I want to minimize the noise for the five people getting emails about this thread.

@lock lock bot locked and limited conversation to collaborators Jul 3, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants