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: fs.readFileSync is not a function #68

Closed
dorner opened this issue Feb 17, 2015 · 2 comments
Closed

TypeError: fs.readFileSync is not a function #68

dorner opened this issue Feb 17, 2015 · 2 comments

Comments

@dorner
Copy link

dorner commented Feb 17, 2015

I'm trying to run EJS strictly in a browser, no Node.js. Here's my code:

ejs.renderFile('/wishabi/tag/templates/tag_pane', {
  item: feature.item,
  displayTypes: this.mapData.displayTypes,
  qcMode: $j('#qc_mode').is(':checked')
}, {client: true}, function(template) {
  $('#tag-body').html(template);
});

When I run this, the result is "TypeError: fs.readFileSync is not a function". Looking at ejs.js in the latest release, I see no definition of this function anywhere, although it's called multiple times from the code. Is something broken?

@mde
Copy link
Owner

mde commented Feb 17, 2015

You should not be calling renderFile in a browser. The filesystem is not accessible in the browser. You should be using the Browserified ejs.js or ejs.min.js provided in a release (https://github.com/mde/ejs/releases/latest), and calling ejs.render.

@TimothyGu
Copy link
Collaborator

See an example for compiling EJS templates in the browser on https://github.com/mde/ejs/blob/master/examples/client-compilation.html

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

3 participants