【问题标题】:fix module.js:328 throw err;修复 module.js:328 抛出错误;
【发布时间】:2018-06-15 01:20:37
【问题描述】:

我正在通过一些教程学习 nodejs,到目前为止一切顺利。现在我遇到了一个错误,我被卡住了。谁能帮帮我。

这是我的 app.js 文件

var greet5 = require('/greet5');
greet5.greet();

这是我的 greet5.js 文件,它与 app.js 位于同一目录中

var greeting = "Hello from Revieling Module pattern";

function greet(){
    console.log(greeting);
}

module.exports = {
    greet : greet
}

当我在终端上运行 node app.js 时,这是我面临的错误。

 module.js:328
        throw err;
        ^

Error: Cannot find module '/greet5'
    at Function.Module._resolveFilename (module.js:326:15)
    at Function.Module._load (module.js:277:25)
    at Module.require (module.js:354:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (/home/pankaja/Nodejs/Tests/23-Module Patterns/app.js:19:14)
    at Module._compile (module.js:410:26)
    at Object.Module._extensions..js (module.js:417:10)
    at Module.load (module.js:344:32)
    at Function.Module._load (module.js:301:12)
    at Function.Module.runMain (module.js:442:10)

谁能帮我解决这个问题。谢谢

【问题讨论】:

  • 您的要求中似乎缺少了表示“来自当前目录”的./require('/greet5')。投票结束是一个错字。供参考:nodejs module search algorithm.
  • 哦。非常感谢。没看到

标签: javascript node.js node-modules


【解决方案1】:

运行nodejs install后出现nodejs项目的README.md文件,说明如何通过nodejs运行web应用。

它说你必须在命令行上执行npm run dev

这里是默认的 README.md:

# Front End Boilerplate
Front-end boilerplate for creating new web projects with Gulp.js and everything you need to get started.
# Getting Started
Required! Gulp installed `npm install -g gulp`
```
$ cd html-boilerplate
$ npm install
$ npm run dev  
```
# Build to production
```
$ npm run build
```
Thank you for your suggestions!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-03-26
    • 2015-04-07
    • 2018-06-18
    • 1970-01-01
    • 2018-02-26
    • 2018-05-30
    • 2013-01-26
    • 1970-01-01
    相关资源
    最近更新 更多