如何解决尝试使用Typescript构建Node.js应用时生成或测试错误
我正在使用只能从命令行运行的typescript构建node.js应用。
我的package.json中包含以下内容:
unitTests = testGroup "All Unit Tests"
[ testCase "A 3-Vector has x,y and z components" $ do
let v = Vec 1.0 2.0 3.0
assertEqual [] (x v) 1.0
assertEqual [] (y v) 2.0
assertEqual [] (z v) 3.0
]
{
"type": "module","main": "dist/index.js","scripts": {
"test": "npx jest","start": "node dist/index.js","build": "npx tsc --build tsconfig.json"
},"devDependencies": {
"jest": "^26.6.1","ts-jest": "^26.4.2","typescript": "^4.0.3"
},"dependencies": {
"@types/jest": "^26.0.15","@types/node": "^14.14.2"
}
}
以及以下目录结构:
我所有的测试都能正常运行并通过,因此node / typescript在读取和处理它们时没有问题:
打字稿可以很好地建立文件。但是,当我尝试启动内置版本时,出现错误{
"include": ["src"],"compilerOptions": {
"target": "es6","module": "esnext","sourceMap": true,"outDir": "./dist","rootDir": "./src","strict": true,"strictPropertyInitialization": false,"moduleResolution": "node","baseUrl": "./","paths": {
"*": ["node_modules/*"]
},"esModuleInterop": true,"skipLibCheck": true,"forceConsistentCasingInFileNames": true
}
}
:
即使文件的相对路径绝对正确。
我尝试了不同package.json Error [ERR_MODULE_NOT_FOUND]: Cannot find module
值,tsconfig.json type
和module
值的许多不同排列,但似乎无法弄清楚使构建正常工作。
有什么想法吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。