2013-03-08 173 views
5

Im對節點j新增。我使用化合物Js來創建crud操作。錯誤:無法找到模塊'jade〜'

該應用程序是工作的罰款,直到我試圖提醒值,在此之後,我發現了錯誤

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) 

如何解決這個

我的指數

#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. 
    - } 

佈局文件

!!! 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') 

回答

4

The issue was with Fedora-16我正在努力。編輯時創建的臨時文件,即'index.jade〜'未被清除,因此問題出現了。

問題時可以使用Fedora-16無論是解決刪除臨時文件「index.jade〜」重命名節點模塊「玉」到「玉〜」

1

呃,你幾乎可以肯定有require('jade~')與一個簡單的錯字,你只想要require('jade')。檢查您的快遞app.engine('jade')線路是另一個可能的嫌疑犯。

+0

要檢查哪個文件? – Okky 2013-03-08 08:27:07

+0

該應用程序工作正常,直到我添加了一個提醒。 – Okky 2013-03-08 08:28:13

+1

您可能已將您的文件命名爲'server.js'或'app.js'。有限的證據強烈地指向一個非常簡單的基本錯字。搜索你的文件「玉〜」並修復它,然後繼續你的生活。你認爲它工作正常,直到你添加了警報,但你肯定是誤導了。 node.js中沒有警報,瀏覽器中發生的事情不會導致節點找不到玉石模塊。 – 2013-03-08 08:34:29

17

我有相當同樣的問題,但「無法找到模塊'玉'」,而不是'玉〜';我很確定我已經做了「npm install jade」。經過一段時間的研究後,我發現我的問題是因爲我在本地安裝了玉器的同時在全球安裝了express,參考此幫助https://www.openshift.com/forums/express/nodejs-and-jade-error-cannot-find-module-jade我解決了我的問題..我在此處發佈它,認爲它可以幫助其他面臨相同問題的人我:)

9

對我來說,這是問題原來是不同的。 我已經安裝了玉器,並在當地和全球範圍內表達,希望他們能夠以某種方式找到對方,但還是表示抱怨玉器。看着

我的錯誤是這樣的:

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) 

,如果你看到這條線:

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

你會看到,它不是NPM安裝的全局或局部的默認位置.. 所以作爲解決辦法,我在以下文件夾中安裝了玉石

cd /Users/ajeetganga/node_modules/ 
npm install jade 

I認爲即使我已經從文件夾/ Users/ajeetganga /安裝了jade,但它從未嘗試過,它仍然有效。 :)

+0

我手動創建快捷項目並在eclipse上運行時,有同樣的錯誤堆棧跟蹤。我按照你在項目的根源建議的方式安裝了玉器,它工作正常。 – Venkat 2014-03-19 02:10:31

1

我在用Emacs編輯一個jade文件後得到了同樣的問題。解決方案很簡單:找到jade〜文件並將其刪除。

18

我在nodechool expressworks教程中遇到了同樣的問題。我解決它通過在的package.json的依賴關係:

NPM安裝--save表達玉

+0

這幫了我。讀完之後,我意識到我已經從項目的package.json中刪除了jade模塊,這就是爲什麼沒有找到它。加了回來,做了npm更新,並且一切正常。 – bearvarine 2016-03-22 14:27:54

+0

它也幫了我:) – AnNaMaLaI 2016-08-15 00:41:08

+0

謝謝你。在使用Team Treehouse學習Node.js時,他們對Jade(現在改名爲Pug)進行了一整段討論,並嘗試通過一系列迭代試圖使其發揮作用。學過的知識。 – 2016-08-19 02:10:29

0

我有同樣的問題(玉裝載機在我的打字稿+的WebPack項目)。我通過將jade-loader安裝爲peer-dependency來解決它。