javascript - 将项目转换为 Typescript 路径时遇到问题
问题描述
现在我正在尝试使用这种方法转换这个项目。
所以我首先克隆它:
git clone git@github.com:fireflysemantics/validator.git
然后编辑paths
设置,使其看起来像这样:
"baseUrl": "./", /* Base directory to resolve non-absolute module names. */
"paths": {
"@fs": ["./src"],
"@test": ["./test"]
}, /*
然后我尝试编辑src/container/error/index.ts
它,使其看起来像这样:
export { ObjectErrors } from "@fs/container/error/ObjectErrors";
export { ValidationError } from "./ValidationError";
当我编译 Typescript 时仍然会产生这个错误:
src/container/error/index.ts:1:30 - 错误 TS2307:找不到模块 '@fs/container/error/ObjectErrors'。
1 从“@fs/container/error/ObjectErrors”导出 { ObjectErrors };~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
想法?
打字稿 Github 问题
解决方案
将您的路径属性添加到 tsconfig 文件中的 compilerOptions。
"compileOnSave": false,
"compilerOptions": {
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2017",
"dom"
],
"paths": {
"@app/*": [
"./app/*"
]
}
}
}
推荐阅读
- jquery - 使用键盘进行选择时的事件
- python - 如何为 jupyter notebook 手动安装 chromium?
- angular - PrimeNG 主题字体覆盖 Angular 应用程序字体
- javascript - 如何将 API 响应变量从服务传递到多个控制器
- python-3.x - 船对象如何知道在主屏幕表面的底部居中显示?
- c# - 如何将其他未选择的项目从列表框中复制到另一个
- r - 使用 lapply 或 loop 从矩阵列表中创建多个图形
- reactive-programming - 使用动态查询在 ReactiveMongoRepository 上实现分页和排序
- apache - CNAME 到另一个子域
- c# - 从 c# 中的 html 获取实际的 href 值