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

_input.charCodeAt is not a function #65

Open
dfmartin opened this issue Oct 3, 2016 · 6 comments
Open

_input.charCodeAt is not a function #65

dfmartin opened this issue Oct 3, 2016 · 6 comments

Comments

@dfmartin
Copy link

dfmartin commented Oct 3, 2016

When the website attempts to load the inspector shows the following error:
Uncaught TypeError: this._input.charCodeAt is not a function

Here is my webpack config loader statement:

        {test: /\.pug$/, loader: 'pug-loader'},

I am new to webpack, so it may very well be me. I was able to get pug-html-loader working, but would rather stick with the folks that created pug. If it is of any importance, I am using this in an Angular2 app.

@tro3
Copy link

tro3 commented Oct 18, 2016

I see the same thing, also in an Angular 2 app.

The component:

@Component({
  selector: 'home',
  templateUrl: 'home.component.jade',
  styleUrls: [
    'home.component.css',
  ]
})
export class HomeComponent {}

and webpack config:

{ test: /\.jade$/, loader: 'pug-loader' }`

@fklingler
Copy link

fklingler commented Nov 10, 2016

You have to use this syntax:

@Component({
    template: require('./home.component.jade')()
})

@jspizziri
Copy link

@fklingler, thanks for your answer, fixed my issue. Could you please explain why this is the case?

@fklingler
Copy link

Unlike pug-html-loader, the require('file.pug') method does not return a string of the html.

It returns a template function (as indicated, maybe not clearly enough, in the README).
This function takes a "locals" object as parameter, so you can pass it variables that are handled in the pug template.
Since Angular2 components already handle these variables, you don't have to pass any object, but you still have to call the template function to get the html string, hence the require('file.pug')() syntax.

To have consistency with other loaders, I think it would be great to have an option the loader query to get the string directly instead of the template function.

@jspizziri
Copy link

@fklingler, thank you!

@zhekaus
Copy link

zhekaus commented Feb 8, 2017

Guys,
Can’t help but ask … is there a way to get rid of require in templates and @component with this loader or any other?
It looks really ugly:

…
@Component({
  selector: 'app-home',
  // templateUrl: './home.component.pug',
  template: require('./home.component.pug')(),
 
p Home works!
div
    img(src=require('../../assets/img/my-image.jpg'))
    //img(src='../../assets/img/my-image.jpg')

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

5 participants