尝试使用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
  ]

tsconfig.json中的以下内容

{
  "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"
  }
}

以及以下目录结构:

dirs

我所有的测试都能正常运行并通过,因此node / typescript在读取和处理它们时没有问题:

tests pass

打字稿可以很好地建立文件。但是,当我尝试启动内置版本时,出现错误{ "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 } }

import error

即使文件的相对路径绝对正确。

relative path

我尝试了不同package.json Error [ERR_MODULE_NOT_FOUND]: Cannot find module值,tsconfig.json typemodule值的许多不同排列,但似乎无法弄清楚使构建正常工作。

有什么想法吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)