typescript - tsconfig 已设置路径但不编译别名
问题描述
使用tsc编译代码的时候发现我的别名并没有转换,但是我已经配置了Paths,这里是tsconfig.json
{
"compilerOptions": {
// https://github.com/TypeStrong/ts-loader/issues/1061
"target": "ES5",
"lib": ["dom", "dom.iterable", "esnext"],
"paths": {
"@/*": ["./src/*"],
"doc/*": ["./site/*"],
"docs/*": ["./site/Components/*"],
"ethan/*": ["./src/*"],
"ethan": ["./src/index.ts"]
},
"rootDir": "src",
"outDir": "publish/css",
"experimentalDecorators": true,
"allowJs": true,
"checkJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"module": "CommonJS",
"moduleResolution": "node",
"resolveJsonModule": true,
"jsx": "react",
"strict": false,
"noImplicitAny": false,
"suppressImplicitAnyIndexErrors": true,
"baseUrl": "./",
"strictNullChecks": false,
"alwaysStrict": false,
"downlevelIteration": true,
},
"include": ["src"],
"exclude": ["node_modules", "ssh-client", "webpack", "scripts", "docs-pages","publish"]
}
代码的编译文件部分之一是here
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getLocale = exports.setLocale = void 0;
// @ts-nocheck
var objects_1 = require("@/utils/objects");
我的代码哪里错了
谢谢~~~
解决方案
您可能必须为此安装其他依赖项,例如module-alias或tsconfig-paths
在我看来,在编译期间解析路径会更容易,但正如 TS 团队所说,在某些使用符号链接的环境中它会变得复杂。
推荐阅读
- python - 从列表和字典中创建给定值的字典
- google-chrome - VS2017 Chrome 浏览器调试器“对象引用未设置为对象的实例”
- c# - “条件表达式中的数据类型不匹配”疑难解答。在 MS Access Insert.Into 期间
- python - 如何在 CPLEX Python 中设置包含指标函数的目标函数?
- asp.net - 在 ASP.Net Core MVC 中,ControllerBase.StatusCode() 中使用的“价值”是什么?
- java - Spring Batch 跳过异常未按预期工作
- excel - 使用不断变化的源数据更改数据透视表列过滤器
- c++ - 段错误:链表节点插入函数 [C++]
- python - Python 3.6 正在打印文字字符 \t 和 \n
- angular - 上下文。$隐式。不是功能打字稿错误