swagger-ui: ReferenceError: Handlebars is not defined
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;
About this issue
- Original URL
 - State: closed
 - Created 9 years ago
 - Comments: 15 (4 by maintainers)
 
Hi, have you tried importing the modules in ES5 way?
var Handlebars = require('handlebars');Does that change anything?