9

Im new to node js. I used Compound Js to create a crud operation.

The app was working fine till i tried to alert a value, after that I'm getting the error

500 Error: Cannot find module 'jade~'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:362:17)
at require (module.js:378:17)

How to resolve this

My index

#tabs
  ul
    li
      a(href='#tabs-1') New Leave
    li
      a(href='#tabs-2') Index of Leave
  #tabs-1
    .page-header
      h1 New employee

    - var form = formFor(employee, {action: pathTo.employees(), method: 'POST', id: "employee_form", class: 'form-horizontal'})

    != form.begin()
    != errorMessagesFor(employee) 
    .control-group
      != form.label("code", false, {class: "control-label"})
      .controls
        != form.input("code")
    .control-group
     != form.label("description", false, {class: "control-label"})
      .controls
        != form.input("description")
    .control-group
      != form.label("applicable", false, {class: "control-label"})
      .controls
        != form.input("applicable")
    .control-group
      != form.label("cForward", false, {class: "control-label"})
      .controls
        != form.checkbox("cForward")
    .control-group
      != form.label("limit", false, {class: "control-label"})
      .controls
        != form.checkbox("limit")
    .control-group
      != form.label("lop", false, {class: "control-label"})
      .controls
        != form.checkbox("lop")
    .control-group
      != form.label("od", false, {class: "control-label"})
      .controls
        != form.checkbox("od")
    .control-group
      != form.label("co", false, {class: "control-label"})
      .controls
        != form.checkbox("co")
    .control-group
      != form.label("lrevision", false, {class: "control-label"})
      .controls
        != form.checkbox("lrevision")
    .control-group
      != form.label("active", false, {class: "control-label"})
      .controls
        != form.checkbox("active")
    .form-actions
      != form.submit('<i class="icon-ok icon-white"></i>  Create employee', {class: 'btn btn-primary'})
      span= ' or '
      != linkTo('Cancel', pathTo.employees(), {class: 'btn'})
    != form.end()
  #tabs-2
    .page-header
      h1 Index of employees


    .row
      .span12
         p
            != linkTo('<i class="icon-plus icon-white"></i> New employee', path_to.new_employee(), {class: 'btn btn-primary'})

    - if (employees.length) {
    .row
      .span12
         table.table.table-striped
           thead
             tr
               th ID
               th.span3 Actions
           tbody
             - employees.forEach(function (employee) {
             tr
               td
                 != linkTo('employee #' + employee.id, path_to.employee(employee))
               td
                 != linkTo('<i class="icon-edit"></i> Edit', pathTo.edit_employee(employee), {class: 'btn btn-mini'}) + ' '
                 != linkTo('<i class="icon-remove icon-white"></i> Delete', pathTo.employee(employee), {class: 'btn btn-mini btn-danger', method: 'delete', remote: true, jsonp: '(function (u) {location.href = u;})'})
             - });
    - } else{
    .row
      .span12
         p.alert.alert-block.alert-info
            strong No employees were found.
    - } 

Layout file

!!! 5
html
  head
    title= title
    != stylesheetLinkTag('http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/themes/base/jquery-ui.css', 'bootstrap', 'application', 'bootstrap-responsive')
    != javascriptIncludeTag('https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/jquery-ui.js', 'rails', 'application')
    script
      $(document).ready(function() {
        $("#tabs").tabs();
      });
    != csrfMetaTag()
  body
    .navbar
        .navbar-inner
            .container
               a.brand(href='#') Project name

    .container
      - var flash = request.flash('info').pop(); if (flash) {
        .alert.alert-info= flash
      - }

      - flash = request.flash('error').pop(); if (flash) {
        .alert.alert-error= flash
      - }

      != body

      hr
      footer
        p © Company 2012
  != contentFor('javascripts')
Okky
  • 10,338
  • 15
  • 75
  • 122

7 Answers7

27

I had the same problem in the nodeschool expressworks tutorial. I solved it by including the dependencies in package.json:

npm install --save express jade
antzshrek
  • 9,276
  • 5
  • 26
  • 43
jeff fried
  • 271
  • 3
  • 2
  • This helped me. After reading, I realized that I had somehow deleted the jade module from my project's package.json, and that's why it was not found. Added it back, did the npm update, and everything worked. – bearvarine Mar 22 '16 at 14:27
  • It helped me too :) – AnNaMaLaI Aug 15 '16 at 00:41
  • Thank you for this. Was using Team Treehouse to learn Node.js and they had a whole section on Jade (now renamed Pug) and went through a bunch of iterations trying to get this to work. Lesson learned. – Joe Hill Aug 19 '16 at 02:10
  • Much to my and many others surprise, this actually worked for me rather than the default solution. – ASCIIbetical Jan 12 '17 at 16:16
18

I have quite the same issue but "Cannot find module 'jade'", not 'jade~'; and I pretty sure that I already did "npm install jade". After awhile of research, I found out that my problem because I install express globally while jade is installed locally, referenced to this help https://www.openshift.com/forums/express/nodejs-and-jade-error-cannot-find-module-jade I solved my problem.. I post it here thinking that it might help some others whom face the same issue as me :)

Duc To
  • 333
  • 2
  • 6
11

For me this was the issue turned out to be different. I had installed jade and express both locally and globally in hope they will find each other somehow, but still express was complaining about the jade.

My error looked like this :

Express server listening on port 3000
Error: Cannot find module 'jade'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at new View (/Users/ajeetganga/node_modules/express/lib/view.js:43:49)
    at Function.app.render (/Users/ajeetganga/node_modules/express/lib/application.js:488:12)
    at ServerResponse.res.render (/Users/ajeetganga/node_modules/express/lib/response.js:798:7)
    at exports.index (/Users/ajeetganga/Documents/WORKSPACE/TinyUrl/MyTinyUrl2/routes/index.js:7:7)
    at callbacks (/Users/ajeetganga/node_modules/express/lib/router/index.js:164:37)
    at param (/Users/ajeetganga/node_modules/express/lib/router/index.js:138:11)

if you observe this line :

at new View (/Users/ajeetganga/node_modules/express/lib/view.js:43:49)

You will see that it is not the default location for npm installation for global or local .. So as a work around, i installed jade in following folder

cd /Users/ajeetganga/node_modules/
npm install jade

I think it would have worked even if I would have installed jade from the folder /Users/ajeetganga/ but never tried. :)

Ajeet Ganga
  • 8,353
  • 10
  • 56
  • 79
  • I had the same error stack trace while manually creating the express project and running on eclipse. I installed the jade as you suggested at root of the project, it worked. – Venkat Mar 19 '14 at 02:10
5

The issue was with Fedora-16 that i was working on. The temp file created while editing ie., 'index.jade~' was not cleared and thus the issue came.

The issue can be resolved in Fedora-16 by either deleting the temp file 'index.jade~' or by renaming the node module 'jade' to 'jade~'

Okky
  • 10,338
  • 15
  • 75
  • 122
2

Uh, you almost certainly have require('jade~') with a simple typo where you want just require('jade'). Check your express app.engine('jade') line as another likely suspect.

Peter Lyons
  • 142,938
  • 30
  • 279
  • 274
  • 1
    You have probably named your file `server.js` or `app.js`. The limited available evidence points STRONGLY at a very simple, basic typo. Search your files for `jade~` and fix it, then go on with your life. You think it was working fine until you added an alert, but you are surely misguided. There is no alert in node.js and what happens in the browser isn't going to cause node to fail to find the jade module. – Peter Lyons Mar 08 '13 at 08:34
  • there is nothing there as jade~ – Okky Mar 08 '13 at 09:39
  • Lysons: There is nothing there as jade~ in the app. I searched the whole files – Okky Mar 08 '13 at 09:46
  • Update the question. Post your `.js` files. Your `.jade` files are irrelevant. – Peter Lyons Mar 08 '13 at 14:38
  • @Lysons can you specify which file? – Okky Mar 10 '13 at 08:56
  • No, the error message doesn't specify, so I cannot. I don't have access to your source code and am not clairvoyent. Post your .js files like I asked. Otherwise, get help from someone local. You are not providing enough information here for someone to help you remotely. – Peter Lyons Mar 10 '13 at 15:57
2

I got the same issue after editing a jade file with Emacs. The solution is quite simple: find the jade~ file and delete it.

Yale Huang
  • 653
  • 5
  • 4
1

I had the same issue (jade-loader in my typescript + webpack project). I resolved it by installing jade-loader as peer-dependency.

Ihor Pavlyk
  • 1,111
  • 13
  • 10