Daniel Limia Aspas
Daniel Limia Aspas

Reputation: 1

Uncaught ReferenceError: JST is not defined on Sails 0.11

while using Sails I get this error Uncaught ReferenceError: JST is not defined on the chrome console everytime this line of code:

JST['SailsApp/assets/templates/addUser.ejs']( obj )

The content of the addUser.ejs file is:

<tr data-id="<%= user.id %>" data-model="user">
  <% if (user.online) { %>
  <td><span class="fa fa-circle fa-lg fa-circle-green"></span></td>
  <% } else { %>
  <td><span class="fa fa-circle fa-lg fa-circle-red"></span></td>
  <% } %>

  <td><%= user.id %></td>
  <td><%= user.name %></td>
  <td><%= user.title %></td>
  <td><%= user.email %></td>

  <% if (user.admin) { %>
  <td> <span class="glyphicon glyphicon-king" > </span></td>
  <% } else { %>
  <td> <span class="glyphicon glyphicon-user" > </span></td>
  <% } %>

  <td><a href="/user/show/<%= user.id %>" class="btn btn-sm btn-primary">Show</a> </td>
  <td><a href="/user/edit/<%= user.id %>" class="btn btn-sm btn-warning">Edit</a> </td>
  <td>
    <form action="/user/destroy/<%= user.id %>" method="POST">
      <input type="hidden" name="_method" value="delete"/>
      <input type="submit" class="btn btn-sm btn-danger" value="Delete"/>
      <input type="hidden" name="_csrf" value="<%= _csrf%>" />
    </form>
  </td>
</tr>

The compiled .jst file is not appearing in .tmp/public folder, and if I run sudo grunt jst manually then it's created but the chrome console continues giving the same error.

Any help would be much appreciated.

Thanks in advance!

Upvotes: 0

Views: 273

Answers (1)

chris
chris

Reputation: 21

I had the same problem recently. Under 'tasks/register/compileAssets.js', try moving jst:dev below copy:dev.

module.exports = function (grunt) {
  grunt.registerTask('compileAssets', [
    'clean:dev',
    'less:dev',
    'copy:dev',
    'jst:dev',
    'coffee:dev'
  ]);
};

It seems that the jst:dev task is looking for the template files in the .tmp/ dir, but they aren't moved from assets/ until the copy task executes. You'll see this if you run grunt and get an error like:

Running "jst:dev" (jst) task
>> Destination not written because compiled files were empty.

Upvotes: 0

Related Questions