gulp-community / gulp-haml

gulp plugin for Haml
MIT License
25 stars 20 forks source link

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

Open martynbiz opened 7 years ago

martynbiz commented 7 years ago

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

stephenlacy commented 7 years ago

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.

bstrilziw commented 7 years ago

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.

rowild commented 7 years ago

Can confirm the above error...

stephenlacy commented 7 years ago

Please open the issue on the relevant haml project.

AnalyzePlatypus commented 7 years ago

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.)

stephenlacy commented 7 years ago

Sounds like it is unmaintained....

VladG0r commented 7 years ago

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.

AnalyzePlatypus commented 7 years ago

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'
  }) 
)
VladG0r commented 7 years ago

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

AnalyzePlatypus commented 7 years ago

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.

VladG0r commented 7 years ago

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

AnalyzePlatypus commented 7 years ago

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)

VladG0r commented 7 years ago

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.

AnalyzePlatypus commented 7 years ago

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

<rant>

The creationix lib doesn't seem to be maintained.

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)

VladG0r commented 7 years ago

I just found Pug, best replacement for Haml.

ycrepeau commented 6 years ago

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