gulp-haml icon indicating copy to clipboard operation
gulp-haml copied to clipboard

"TypeError: undefined is not a function" in generated file

Open martynbiz opened this issue 7 years ago • 16 comments

Hi, I have the following HAML:

!!! 5
%html.no-js{:lang => "en"}
  %head
    %title Our Awesome Haml Template
  %body
    %p Abstracting HTML since 2006

But it's outputting the following error message in the generated file:

<pre class='error'>TypeError: undefined is not a function
    at eval (eval at &lt;anonymous&gt; (/Users/mbiz/www/suau/node_modules/haml/lib/haml.js:595:29), &lt;anonymous&gt;:2:15)
    at Function.&lt;anonymous&gt; (/Users/mbiz/www/suau/node_modules/haml/lib/haml.js:595:11)
    at execute (/Users/mbiz/www/suau/node_modules/haml/lib/haml.js:602:8)
    at Function.render (/Users/mbiz/www/suau/node_modules/haml/lib/haml.js:587:12)
    at hamlStream (/Users/mbiz/www/suau/node_modules/gulp-haml/index.js:31:6)
    at wrappedMapper (/Users/mbiz/www/suau/node_modules/map-stream/index.js:84:19)
    at Stream.stream.write (/Users/mbiz/www/suau/node_modules/map-stream/index.js:96:21)
    at write (/Users/mbiz/www/suau/node_modules/gulp/node_modules/vinyl-fs/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:623:24)
    at flow (/Users/mbiz/www/suau/node_modules/gulp/node_modules/vinyl-fs/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:632:7)
    at DestroyableTransform.pipeOnReadable (/Users/mbiz/www/suau/node_modules/gulp/node_modules/vinyl-fs/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:664:5)</pre>

It seems to work if I remove the {:lang => "en"} part, but I want to put a lang attribute here, so removing it is not an option.

Also, if it helps, here's how I'm declaring my gulpfile task:

gulp.task('haml', function () {
    return gulp.src('src/haml/**/*.haml')
        .pipe(haml({ext: '.html'}))
        // .pipe(prettify({indent_char: ' ', indent_size: 4}))
        .pipe(gulp.dest('./'));
});

Anyway, let me know if you need any more info :) Thanks

martynbiz avatar Mar 02 '17 16:03 martynbiz

Can you try with the TJ haml lib?

compiler: 'visionmedia'

That error is weird, https://haml2erb.org/ compiles the code correctly. I'd suggest opening an issue on the relevant project as well since I don't alter the project here.

stephenlacy avatar Mar 02 '17 16:03 stephenlacy

I've got the same error.

gulp.task('haml', function () {
	gulp.src('./Views/**/*.haml')
			.pipe(haml({
				compiler: 'visionmedia'
			}))
			.pipe(gulp.dest('./'));
});

will produce the following error:

[18:23:44] Finished 'haml' after 7.91 ms
stream.js:74
      throw er; // Unhandled stream error in pipe.
      ^

SyntaxError: (Haml): Unexpected token :
    at Function (native)
    at /home/benjamin/projects/iframedepo/node_modules/hamljs/lib/haml.js:662:14
    at Object.HAML.render (/home/benjamin/projects/iframedepo/node_modules/hamljs/lib/haml.js:676:6)
    at hamlStream (/home/benjamin/projects/iframedepo/node_modules/gulp-haml/index.js:31:6)
    at wrappedMapper (/home/benjamin/projects/iframedepo/node_modules/map-stream/index.js:84:19)
    at Stream.stream.write (/home/benjamin/projects/iframedepo/node_modules/map-stream/index.js:96:21)
    at write (/home/benjamin/projects/iframedepo/node_modules/vinyl-fs/node_modules/readable-stream/lib/_stream_readable.js:623:24)
    at flow (/home/benjamin/projects/iframedepo/node_modules/vinyl-fs/node_modules/readable-stream/lib/_stream_readable.js:632:7)
    at DestroyableTransform.pipeOnReadable (/home/benjamin/projects/iframedepo/node_modules/vinyl-fs/node_modules/readable-stream/lib/_stream_readable.js:664:5)
    at emitNone (events.js:67:13)

Setting the compiler to the default creationix will compile, but with the same error as before.

bstrilziw avatar Mar 21 '17 17:03 bstrilziw

Can confirm the above error...

rowild avatar Jun 07 '17 07:06 rowild

Please open the issue on the relevant haml project.

stephenlacy avatar Jun 07 '17 14:06 stephenlacy

The HAML-js lib has a number of issues (21 as of June 2017). creationix HAML-js does not report file names or line numbers when erroring, but will give you it's own useless internal stack trace in the output file. When possible, try the other compiler or the original Ruby lib (Here's a gulp wrapper. It calls out to Ruby, is slow, but it works.)

AnalyzePlatypus avatar Jun 19 '17 20:06 AnalyzePlatypus

Sounds like it is unmaintained....

stephenlacy avatar Jun 20 '17 01:06 stephenlacy

with this library you can't use regular Ruby syntax (for attributes) like: %html.no-js{:lang => "en"} you should use Ruby1.9 syntax: %html.no-js{lang:"en"} Author, please make the note about required syntax.

VladG0r avatar Jun 21 '17 08:06 VladG0r

That's an issue in the creationix complier, which appears to be unmaintained. Use the alternate compiler instead:

var haml = require('gulp-haml')

gulp.src('path/to/stuff')
  .pipe( haml({
    compiler: 'visionmedia'
  }) 
)

AnalyzePlatypus avatar Jun 21 '17 09:06 AnalyzePlatypus

AnalyzePlatypus, i did, both compilers: creationix and visionmedia are working only with Ruby1.9 syntax.

VladG0r avatar Jun 21 '17 10:06 VladG0r

Hmm. File an issue on the visionmedia compiler here. My experience with both compilers has not been great. I've switched to gulp-haml-ruby, which uses the original Ruby implementation. However, it calls out to the command line and Ruby, so it's very slow (3s to launch on my 15" MBP). The benefit: it actually implements the entire haml spec.

AnalyzePlatypus avatar Jun 21 '17 10:06 AnalyzePlatypus

AnalyzePlatypus, that's why im not using gulp-haml-ruby, because Ruby requests are slow.

VladG0r avatar Jun 21 '17 10:06 VladG0r

Oh, absolutely. But it seems like the best option out there, short of switching to a different template language. (Better slow and functional than fast and broken)

AnalyzePlatypus avatar Jun 21 '17 10:06 AnalyzePlatypus

AnalyzePlatypus, to be honest, it's not broken. Compiler works perfect, but with Ruby1.9 syntax only and has no other Ruby features like: include from other file. Because it's just a compiler, not a full-functionality language.

VladG0r avatar Jun 21 '17 10:06 VladG0r

I don't know. Both compilers have their flaws.

<rant>

The creationix lib doesn't seem to be maintained.

  • Multiline attributes, strings and comments: broken
  • Obscure compilation errors lacking basic info (what went wrong?), file names, and line numbers.
  • Silently fails on single quotes
  • "Secret" errors that do not get thrown, but instead wind up in the output file with obscure stack traces.

Running the code through the canonical Ruby gem passes it with no errors. Same on the haml2erb online convertor

The visionmedia compiler gives me irreproducible issues with my indenting. Again, the original Ruby implementation is perfectly happy with it.

In short: wrapping a HAML lib in a gulp plugin: Great idea! Are there any decent JS implementations of HAML? Maybe, but I haven't found one yet.

Don't get me wrong, this plugin might be perfectly suited for your needs. But I'm limping back to the painfully slow (but functional) Ruby version, at least until the state of the compilers improves.

Ruby has it's own issues, and performance is truly terrible, but at least they're known issues.

</rant>

(My apologies)

AnalyzePlatypus avatar Jun 21 '17 11:06 AnalyzePlatypus

I just found Pug, best replacement for Haml.

VladG0r avatar Jun 21 '17 15:06 VladG0r

Replace Haml with Pug and re-code your 10000 lines of code.

ycrepeau avatar Jan 30 '18 21:01 ycrepeau