我使用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/