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

ReferenceError: Handlebars is not defined #1551

Closed
RaviVaranasi opened this issue Aug 20, 2015 · 15 comments
Closed

ReferenceError: Handlebars is not defined #1551

RaviVaranasi opened this issue Aug 20, 2015 · 15 comments

Comments

@RaviVaranasi
Copy link

Trying to generate documentation for endpoint from my api-docs.json definition.

Am i missing something or setting up swagger ui incorrectly ?

Below is the exception

this["Handlebars"]["templates"]["apikey_button_view"] = Handlebars.template({"
                                                        ^
ReferenceError: Handlebars is not defined
  at Object.<anonymous> (/app/node_modules/swagger-ui/dist/swagger-ui.js:9:57)
  at Object.<anonymous> (app/node_modules/swagger-ui/dist/swagger-ui.js:32183:7)

express controller below:

import Handlebars from 'handlebars';
import SwaggerUi from 'swagger-ui';

var app = express();

let swaggerUi = new SwaggerUi({
  url:'/api-docs.json'
});
swaggerUi.load();


// Serve up swagger ui at /docs via static route
var docs_handler = express.static(__dirname + '../../node_modules/swagger-ui/');
app.get(/^\/docs(\/.*)?$/, function(req, res, next) {
    if (req.url === '/docs') { // express static barfs on root url w/o trailing slash
    res.writeHead(302, { 'Location' : req.url + '/' });
    res.end();
    return;
  }
  // take off leading /docs so that connect locates file correctly
  req.url = req.url.substr('/docs'.length);
  return docs_handler(req, res, next);
});
app.get('/api-docs', (req, res) => {
    res.json(swaggerJsonConfig);
});

export default app;
@nikniv
Copy link

nikniv commented Sep 10, 2015

Hi, have you tried importing the modules in ES5 way?
var Handlebars = require('handlebars');
Does that change anything?

@oaktowner
Copy link

I get the same behavior -- note that I'm not importing the Handlebars module, this seems to be done in the swagger-ui.js file itself.

@fehguy
Copy link
Contributor

fehguy commented Nov 4, 2015

Howdy, if you're looking to set up swagger-ui, you don't need to use express as an app server. I may be answering the wrong question, but the easiest way to do this is:

  • Clone swagger-ui from [email protected]:swagger-api/swagger-ui.git
  • Run http-server from the dist folder:
npm install -g http-server
http-server --cors

then you can open swagger-ui at http://localhost:8080

@Chris0lsen
Copy link

Hi, similar issue here. I navigated to the node_modules/swagger-ui directory and ran npm install handlebars from there, but got the same error. THEN I entered node_modules/swagger-ui/dist/swagger-ui.js and added var Handlebars = require('handlebars'), and got the following error:

Error: Template was precompiled with an older version of Handlebars than the current runtime. Please update your precompiler to a newer version (>= 4.0.0) or downgrade your runtime to an older version (>= 2.0.0-beta.1).

So that's confusing. Anybody else seeing this?

@fehguy
Copy link
Contributor

fehguy commented Mar 10, 2016

@Chris0lsen can you please rm -rf the node_modules and run npm i again?

@ctippur
Copy link

ctippur commented Mar 23, 2016

Any updates on this? I am facing the same issue.

@ctippur
Copy link

ctippur commented Mar 24, 2016

I have removed node_modules and tried it. I get the same error.

@GreenPioneer
Copy link

I am having the same problem

has anyone been able to solve this

@GreenPioneer
Copy link

@RaviVaranasi @Chris0lsen @fehguy /\

@maxiejbe
Copy link

Same issue here. For now I'm just using the online docs generator: http://generator.swagger.io/

@ChristianRich
Copy link

+1

I have no idea how to run this inside my express app - should be dead simple but getting same errors as your guys.

@GreenPioneer
Copy link

@ChristianRich

Check out my way around it and note the version im on

@webron
Copy link
Contributor

webron commented Mar 20, 2017

Anyone wants to give it a spin with 3.0?

@GreenPioneer
Copy link

GreenPioneer commented Mar 20, 2017

@webron yea ill give it a try in my meanstackjs

@webron
Copy link
Contributor

webron commented Jun 9, 2017

This should no longer be an issue with 3.X.

@webron webron closed this as completed Jun 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants