为什么Typescript tsc输出生成的文件不在我的repo中



这是我的存储库https://github.com/inspiraller/tsc-example

这是我的tsconfig.json

{
"compilerOptions": {
"baseUrl": "./",
"allowJs": true,
"strict": true,
"target": "es6",
"module": "commonjs",
"lib": ["dom", "es6", "es5", "es2017", "esnext.asynciterable"],
"sourceMap": true,
"moduleResolution": "node",
"removeComments": true,
"noImplicitThis": true,
"noUnusedLocals": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"esModuleInterop": true,
"noUnusedParameters": false,
"paths": {
"src/*": ["./src/*"]
},
"declaration": true,
"rootDir": "./",
"outDir": "dist"
},
"exclude": ["node_modules", "dist", "__tests__", "jest.config.js"],
"include": [ "/src/*", "@types"]
}

这是我的index.ts

type mystring = string;
type TFunc = (x: mystring) => string;
const func: TFunc = (str) => str + str;
const get = () => func('hello');
export default get;

我的package.json只有一个包typescript和一个用于构建的脚本

{
"name": "tsc-example",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo "Error: no test specified" && exit 1",
"build": "tsc"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"typescript": "^4.1.3"
}
}

当我像这样运行构建时

npm run build 

我得到这个错误:

error TS6059: File '/src/config.ts' is not under 'rootDir' 'c:/projects/tsc-example'. 'rootDir' is expected to contain all source files.
error TS6059: File '/src/hot.tsx' is not under 'rootDir' 'c:/projects/droplets/tsc-example'. 'rootDir' is expected to contain all source files.
error TS6059: File '/src/index.tsx' is not under 'rootDir' 'c:/projects/droplets/tsc-example'. 'rootDir' is expected to contain all source files.

Found 3 errors.

它确实试图生成这些文件,但它们不在这个repo中,甚至不在这个项目的任何祖先中。(查看了生成的输出后,我可以看到这些文件的内容来自我的另一个repo,但它们不在这个项目中(

  • 配置.ts
  • config.js
  • config.js.map
  • 热.d.ts
  • 热门.js
  • hot.js.map
  • index.d.ts
  • index.js
  • index.js.map

有人能解释为什么会发生这种情况吗?

您在此处用前导/指示了一条路径"include": [ "/src/*", "@types"]。只需像这样删除:

"include": [ "src/*", "@types"]

最新更新