我过去曾经使用过express,但是第一次尝试打字稿。我不确定此错误是否与打字稿有关,但我无法想到可能导致此问题的任何其他原因。我也在使用WSL,但是到目前为止,在节点上我从未发生过任何故障-尽管我没有使用很长时间。
这是导致异常的代码:
import { createSecureServer } from 'http2'
import { readFileSync } from 'fs'
import * as express from 'express'
const key = readFileSync('/etc/ssl/private/selfsigned.key')
const cert = readFileSync('/etc/ssl/certs/selfsigned.crt')
const server = createSecureServer({ key, cert }, express)
server.listen(3000, 'localhost', () => {
console.log('Server is up and running!')
})
这是例外:
TypeError: argument fn must be a function
at Function.wrapfunction [as function] (/mnt/c/Users/caleb/Code/stats-backend/dist/app.js:4355:11)
at populateConstructorExports (/mnt/c/Users/caleb/Code/stats-backend/dist/app.js:10346:45)
at Object.<anonymous> (/mnt/c/Users/caleb/Code/stats-backend/dist/app.js:10128:1)
at c (/mnt/c/Users/caleb/Code/stats-backend/dist/app.js:20255:3584)
at b.require (/mnt/c/Users/caleb/Code/stats-backend/dist/app.js:20255:3346)
at Object.<anonymous> (/mnt/c/Users/caleb/Code/stats-backend/dist/app.js:17789:19)
at c (/mnt/c/Users/caleb/Code/stats-backend/dist/app.js:20255:3584)
at b.require (/mnt/c/Users/caleb/Code/stats-backend/dist/app.js:20255:3346)
at Object.<anonymous> (/mnt/c/Users/caleb/Code/stats-backend/dist/app.js:7329:12)
at c (/mnt/c/Users/caleb/Code/stats-backend/dist/app.js:20255:3584)
package.json:
{
"devDependencies": {
"@types/express": "4.16.1",
"@types/node": "^12.0.4",
"fuse-box": "^3.7.1",
"typescript": "^3.5.1",
"uglify-es": "^3.3.9"
},
"dependencies": {
"express": "4.16.1"
}
}
我做错了什么导致我收到此错误?