sindresorhus / gulp-template

Render/precompile Lodash templates

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Lodash.template undefined

skuester opened this issue · comments

I'm getting a undefined is not a function from index.js:19:31
I entered some debugging logs - the var template (ie: lodash.template) on line 19 is undefined.

That's weird. Works fine in the tests. Try npm cache clean and reinstall it.

Hmm - didn't seem to help. I still get the same error:
image

For now, I've tweaked my local gulp-template package to use the lodash.template package instead of lodash. That seems to do the trick.

same here!

events.js:72
        throw er; // Unhandled 'error' event
              ^
ReferenceError: error is not defined
  at eval (<anonymous>:7:11)
  at template (/Users/flow/dev/slush/slush-base/node_modules/gulp-template/node_modules/lodash/dist/lodash.js:6311:16)
  at DestroyableTransform._transform (/Users/flow/dev/slush/slush-base/node_modules/gulp-template/index.js:24:31)
  at DestroyableTransform.Transform._read (/Users/flow/dev/slush/slush-base/node_modules/gulp-template/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:184:10)
  at DestroyableTransform.Transform._write (/Users/flow/dev/slush/slush-base/node_modules/gulp-template/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:172:12)
  at doWrite (/Users/flow/dev/slush/slush-base/node_modules/gulp-template/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:237:10)

@jdalton any thoughts why this is happening?

An error in your template could cause an error to be thrown as _.template will compile a function to construct your string. If you can catch or inspect the error look for a source property to get the generated template source to help spot the issue.

Looks like maybe your template has an "error" property read like <%= error %> and you're not providing it one in the template data object. Ex:

_.template('<%= error %>')({}); // => ReferenceError: error is not defined

@jdalton Ah, of course, didn't think that the error could come from the template itself.

Yeah, just attach an .on('error, console.error.bind(console)) after the gulpTemplate method in the stream to see the error. Standard node stream stuff.

The missing data object property error can be avoided if you reference the data object itself or provide a variable option to customize it. Ex:

_.template('<%= obj.error %>')({}); // ""
_.template('<%= data.error %>', { variable: 'data' })({}); // ""

Thanks for the hint! One of my templates contained:

  g.notify.onError(
    title: 'Compile Error'
    message: "<%= error.message %>"
  ).apply(@, args)

After fixing this template everything is working fine.

message: "#{error.message}"