node.js - 如何在express中调试TypeError [ERR_INVALID_ARG_TYPE]?

标签 node.js express

我使用express框架开发了一个简单的node js登录应用程序。这是我的文件结构:

  • 垃圾箱
    • www
  • Node 模块
  • 路线
  • 上传
  • 观看次数
  • app.js

当我尝试运行“npm start”时,它显示:

internal/modules/cjs/loader.js:631
    throw new ERR_INVALID_ARG_TYPE('id', 'string', id);
    ^

TypeError [ERR_INVALID_ARG_TYPE]: The "id" argument must be of type 
string. Received type object

什么原因导致这个错误?怎么解决呢?

这是错误堆栈:

13 verbose stack Error: nodeauth@0.0.0 start: `node ./bin/www`
TypeError [ERR_INVALID_ARG_TYPE]: The "id" argument must be of type string. Received type object
at Module.require (internal/modules/cjs/loader.js:631:11)
at require (internal/modules/cjs/helpers.js:22:18)
at Object.<anonymous> (/Users/jiatongli/Desktop/nodeauth/app.js:13:14)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:22:18)

最佳答案

如果您声明 varexpress = require(express) 时不带单引号,可能会出现此错误。修改 varexpress = require('express');而不是 varexpress = require(express);

关于node.js - 如何在express中调试TypeError [ERR_INVALID_ARG_TYPE]?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55205314/

相关文章:

node.js/ express : Sending static files if they exist

node.js - 在 Express Nodejs 中记录用户事件

express - Kafka+API服务架构

node.js - vorpal .validate 抛出错误

javascript - res.redirect 没有重定向到任何地方

node.js + 表达错误 : cannot read property 'url' of undefined

javascript - 无法在模型 `user` 上找到主键属性。所有模型都必须包含一个充当主键的属性

node.js - 如何解决promise.all()并想要删除一个级别的对象

node.js - Node Sass 找不到当前环境的绑定(bind) : Windows 64-bit with Node. js 6.x

node.js - 无法将MongoDB与nodejs连接