9

我是节点 js 的新手。我使用 Compound Js 创建了一个 crud 操作。

该应用程序运行良好,直到我尝试提醒一个值,之后我收到错误

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

7 回答 7

27

我在 nodeschool expressworks 教程中遇到了同样的问题。我通过在 package.json 中包含依赖项来解决它:

npm install --save express jade
于 2015-02-15T04:43:17.997 回答
18

我有完全相同的问题,但是“找不到模块'jade'”,而不是'jade~';我很确定我已经做了“npm install jam”。经过一段时间的研究,我发现我的问题是因为我在全局安装express而在本地安装jade,参考了这个帮助https://www.openshift.com/forums/express/nodejs-and-jade-error-cannot- find-module-jade我解决了我的问题.. 我把它贴在这里,以为它可能会帮助一些与我面临同样问题的其他人:)

于 2013-07-25T03:47:53.710 回答
11

对我来说,这是一个不同的问题。我在本地和全球都安装了玉和快递,希望他们能以某种方式找到对方,但快递仍然在抱怨玉。

我的错误如下所示:

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

我认为即使我从文件夹 /Users/ajeetganga/ 安装了翡翠,它也会起作用,但从未尝试过。:)

于 2013-10-12T19:00:09.270 回答
5

The issue was with Fedora-16我正在研究的。编辑时创建的临时文件,即'index.jade~'没有被清除,因此问题来了。

这个问题可以在 Fedora-16 中通过删除临时文件 'index.jade~'将节点模块 'jade' 重命名为 'jade~' 来解决

于 2013-03-18T06:03:29.433 回答
2

呃,你几乎可以肯定require('jade~')在你想要的地方有一个简单的错字require('jade')。检查您的快递app.engine('jade')线路作为另一个可能的嫌疑人。

于 2013-03-08T08:25:11.440 回答
2

用 Emacs 编辑一个玉文件后,我遇到了同样的问题。解决方法很简单:找到jade~文件并删除。

于 2014-07-13T06:04:36.187 回答
0

我遇到了同样的问题(我的 typescript + webpack 项目中的 jade-loader)。我通过将jade-loader 安装为对等依赖项来解决它。

于 2016-09-26T05:30:51.410 回答