Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Uncaught ReferenceError: Handlebars is not defined#1990

Unanswered
mcasassa-ext asked this question inQ&A
Discussion options

Good afternoon :)
I wanted to reach out as I could not find any solutions through trusty google. At my company we use Handlebars templates to render content at runtime, we are attempting to upgrade our version from 1.3.0 to 4.7.7 but we are running into the error ofUncaught ReferenceError: Handlebars is not defined
We are storing the min file locallyhttps://cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.7.7/handlebars.min.js and importing handlebars into relevant files usingHandlebars = require('handlebars').
After the upgrade it appears that our templates are loading correctly but I need to identify the source of this error so we can begin regression and confirm there is no impact.
Any help is appreciated on this issue and thanks in advance.

You must be logged in to vote

Replies: 3 comments 6 replies

Comment options

Can you provide a reduced test-case that reproduces the error? Otherwise it's hard for me to help you.

You must be logged in to vote
1 reply
@mcasassa-ext
Comment options

Thank you for your response, I will work with my team to implement a test case for this scenario and get the data back here. Please provide specifics if you need them.

Comment options

Good day, I have attempted to implement a test case to share more data but I was unsuccessful as our application broke because of node version. Looked into the code again I found the source of the error "Uncaught ReferenceError: Handlebars is not defined" is originating from a file that looks like it is being generated at runtime templates.js this location is attempting to run a function

this["merlinTemplates"]["abandonPage/abandonPage"] = Handlebars.template(function (Handlebars,depth0,helpers,partials,data) {  this.compilerInfo = [4,'>= 1.0.0'];helpers = this.merge(helpers, Handlebars.helpers); data = data || {};  var buffer = "", stack1, functionType="function", escapeExpression=this.escapeExpression;  buffer += "<div class=\"row pop \">\n<div class=\"pop-wrap\">\n\n</div>\n<div class=\"pop-wrap\">\n       <b>"    + escapeExpression(((stack1 = ((stack1 = (depth0 && depth0.abandonPage)),stack1 == null || stack1 === false ? stack1 : stack1.message)),typeof stack1 === functionType ? stack1.apply(depth0) : stack1))    + "</b>\n    </div>\n    <div class=\"pop-footer right\">\n        <button class=\"text-button button cancel\">"    + escapeExpression(((stack1 = ((stack1 = (depth0 && depth0.buttons)),stack1 == null || stack1 === false ? stack1 : stack1.no)),typeof stack1 === functionType ? stack1.apply(depth0) : stack1))    + "</button>\n        <button class=\"radius grey button continue\">"    + escapeExpression(((stack1 = ((stack1 = (depth0 && depth0.buttons)),stack1 == null || stack1 === false ? stack1 : stack1.yes)),typeof stack1 === functionType ? stack1.apply(depth0) : stack1))    + "</button>\n    </div>\n</div>";  return buffer;  });

This above mentioned function seems have a unique variation for each template we have in our code base, any modification to this file is removed after saving and our local build runs.

More details about our application:
Node Version: 12.19.0
We run vanilla JS, Jquery and utilize handlebars for templating with no html. We do not use Webpack and our installation of handlebars utilizes the CDN min file. Me and my team are currently at a loss of how to resolve this issue nor does it appear that the error being thrown is impacting our functionality. Thank you for your assistance and time with this issue.

You must be logged in to vote
5 replies
@jaylinski
Comment options

In a Node environment, you should import Handlebars like this (and install it via npm):

constHandlebars=require("handlebars");

The CDN min file is optimized for browsers.

@mcasassa-ext
Comment options

We import Handlebars into files using var Handlebars = require('handlebars') Declaration as a Const requires ES6 and we are running ES5.

@jaylinski
Comment options

Are you making sure that the handlebars-cdn-script is loadedbefore the templates are executed?

@mcasassa-ext
Comment options

Yes we have a console output when our application is finished initializing and the Uncaught ReferenceError shows up in the console after that message.

@jaylinski
Comment options

Sorry, but I'm out of ideas.

Comment options

Also we are using Grunt versions: grunt-cli v1.4.3, grunt v1.5.3. I will include our configuration in our Grunt file for Handlebars.

handlebars: {        options: {          namespace: 'merlinTemplates',          processName: function(filePath) {            return filePath.replace(/^templates\//, '')              .replace(/\.hbs$/, '')              .replace(/source\//, '')              .replace(/modules\//, '');          }        },        all: {          files: {            "source/modules/templates.js": ["source/modules/**/*.hbs"]          }        }      }
You must be logged in to vote
0 replies
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Q&A
Labels
None yet
2 participants
@mcasassa-ext@jaylinski

[8]ページ先頭

©2009-2025 Movatter.jp