我是nodejs的新手,但我不断收到此错误

问题描述 投票:0回答:1

我一直收到此错误。我已经两次删除了node.js,然后再次重新安装。同样的错误不断弹出。 error gotten from nodejs

这是我试图导出到index.js文件的person.js文件:

class Person {
    constructor(name, age) {
        this.name = name;
        this.age = age;
    }

    greeting() {
        console.log(`my name is ${this.name}`)
    }
}

module.exports = Person;

这是index.js文件:

const Person = require("./person")

const person1 = new Person ("Philippa", 30)

person1.greeting()

此外,我尝试这样做,但不断出现相同的错误:

const path = require("path")

console.log(__filename)

console.log(__dirname)

编辑:这是我一直无法打开的错误:

enter code here
$ node path.js
internal/modules/cjs/loader.js:985
  throw err;
  ^

Error: Cannot find module 'C:\Users\9470M\Documents\node_crash_course\path.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:982:15)
    at Function.Module._load (internal/modules/cjs/loader.js:864:27)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
    at internal/main/run_main_module.js:18:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}
node.js path export node-modules throw
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.