我正在尝试运行node server.js,但系统提示错误:无法找到模块“C:\用户\用户\OneDrive\桌面\节点\后端\server.js”

6ie5vjzr  于 2022-12-18  发布在  Node.js
关注(0)|答案(1)|浏览(258)
S C:\Users\user\OneDrive\Desktop\node\backend> node server.js
node:internal/modules/cjs/loader:988
  throw err;
  ^

Error: Cannot find module 'C:\Users\user\OneDrive\Desktop\node\backend\server.js'
    at Function.Module._load (node:internal/modules/cjs/loader:833:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:22:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}
PS C:\Users\user\OneDrive\Desktop\node\backend> node server.js
node:internal/modules/cjs/loader:988
  throw err;
  ^

Error: Cannot find module 'C:\Users\user\OneDrive\Desktop\node\backend\server.js'
PS C:\Users\user\OneDrive\Desktop\node\backend> node server.js
node:internal/modules/cjs/loader:988
  throw err;
  ^

Error: Cannot find module 'C:\Users\user\OneDrive\Desktop\node\backend\server.js'
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:985:15)
    at Function.Module._load (node:internal/modules/cjs/loader:833:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:22:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

每当我运行node server.js时,我会得到上面的错误我已经分别运行npm安装,但都是徒劳的

const express = require("express")
var app = express()
const port = 3000

app.get('/', (_req, res) =>{
    res.send('Hello World')
})

app.listen(port, ()=>{
    console.log(`server is running on port number ${port}`)
})

我希望终端到控制台服务器在端口号3000上运行,我安装了express,但被告知MODULE NOT FOUND

zengzsys

zengzsys1#

你的代码看起来很好,应该可以运行,因为你之前使用了npm init -ynpm install express。我想npm start也会给你同样的错误吧?
除此之外,您的代码似乎位于与OneDrive同步的文件夹中...您确定它已正确同步吗?您是否尝试过使用more server.js等字符显示server.js的内容?

相关问题