我的 tsconfig.json
{
"compilerOptions": {
"target": "ES2018",
"module": "CommonJS",
"lib": ["ESNext", "ESNext.AsyncIterable"],
"skipLibCheck": true,
"sourceMap": true,
"outDir": "./dist",
"moduleResolution": "node",
"removeComments": true,
"noImplicitAny": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"noImplicitThis": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"resolveJsonModule": true,
"baseUrl": "./",
"paths": {
"@/*": ["src/*"],
"@config": ["src/config"],
}
},
"exclude": ["node_modules"],
"include": ["./src/**/*.ts"]
}
Run Code Online (Sandbox Code Playgroud)
我非常确定 tsconfig 路径没有任何问题,因为我什至从 IDE 获得了路径自动完成功能。但是当我的代码编译时(tsc --project tsconfig.json)
import { PRODUCTION } from '@config';
// or
import { …Run Code Online (Sandbox Code Playgroud) *.ts我在使用 ts-node运行文件时遇到问题。
我的项目的目录结构如下所示。
-- project dir
-- src
-- services
-- module1
-- file1.ts (classA)
-- file2.ts (classB)
-- index.ts (contains export statements like export * from file1.ts)
-- application.ts
Run Code Online (Sandbox Code Playgroud)
这是我在tsconfig.json文件中配置的内容。
{
"compilerOptions": {
"lib": [
"es2020",
"dom"
],
"baseUrl": ".",
"paths": {
"@src/*": ["src/*"],
"@tests/*": ["tests/*"],
},
"module": "CommonJS",
"target": "es2020",
"strict": true,
"alwaysStrict": true,
"declaration": true,
"noImplicitAny": true,
"strictNullChecks": true,
"noImplicitThis": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"noImplicitReturns": true,
"inlineSourceMap": true,
"inlineSources": …Run Code Online (Sandbox Code Playgroud)