Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
martynbiz opened this issue Mar 2, 2017 · 16 comments
Open

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

martynbiz opened this issue Mar 2, 2017 · 16 comments

Comments

@martynbiz
Copy link

martynbiz commented Mar 2, 2017

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
Copy link
Contributor

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
Copy link

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
Copy link

rowild commented Jun 7, 2017

Can confirm the above error...

@stephenlacy
Copy link
Contributor

Please open the issue on the relevant haml project.

@AnalyzePlatypus
Copy link
Contributor

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
Copy link
Contributor

Sounds like it is unmaintained....

@VladG0r
Copy link

VladG0r commented Jun 21, 2017

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
Copy link
Contributor

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
Copy link

VladG0r commented Jun 21, 2017

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

@AnalyzePlatypus
Copy link
Contributor

AnalyzePlatypus commented Jun 21, 2017

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
Copy link

VladG0r commented Jun 21, 2017

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

@AnalyzePlatypus
Copy link
Contributor

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
Copy link

VladG0r commented Jun 21, 2017

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
Copy link
Contributor

AnalyzePlatypus commented Jun 21, 2017

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)

@VladG0r
Copy link

VladG0r commented Jun 21, 2017

I just found Pug, best replacement for Haml.

@ycrepeau
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants