shannonmoeller / handlebars-layouts

Handlebars helpers which implement layout blocks similar to Jinja, Nunjucks (Swig), Pug (Jade), and Twig.
http://npm.im/handlebars-layouts
MIT License
361 stars 29 forks source link

ReferenceError: Handlebars is not defined #40

Closed kaspar-allenbach closed 6 years ago

kaspar-allenbach commented 6 years ago

This is not partucular a problem of your npm package. I run into this regularely :(

I import handlebars with the standard require code for npm:

var handlebars = require('handlebars'), layouts = require('handlebars-layouts');
handlebars.registerHelper(layouts(handlebars));

This throws the error:

ReferenceError: Handlebars is not defined

I can only include it with this:

import handlebars from 'handlebars';

other npm packages work with with the require command just fine

E.g. this works var c3 = require("c3");

But why?

shannonmoeller commented 6 years ago

Using Node v8.9.3 and Handlebars v4.0.11 this is working fine for me:

const handlebars = require('handlebars');
const layouts = require('../dist/handlebars-layouts');

handlebars.registerHelper(layouts(handlebars));

console.log(handlebars.helpers);

Can you share the entire error with stack trace?

shannonmoeller commented 6 years ago

It's interesting to me that your example error has Handlebars (uppercase "H") and not handlebars (lowercase "h"). Is it possible you have a case error in your actual code?

kaspar-allenbach commented 6 years ago

omg 😫 yes that uppercase H was the problem.