typescript - 打字稿项目对共享项目的引用无法解决
问题描述
我正在尝试在 2 个项目之间使用 Typescript 项目引用:client
并且shared
该client/tsc -b
过程成功。但是,在运行时导入shared
文件失败。
项目结构非常简单:
./client
./client/tsconfig.json
./client/src
./client/src/app-load.tsx
./shared
./shared/tsconfig.json
./shared/src
./shared/src/validation-utils.ts
./client/tsconfig.json的内容
{
"compilerOptions": {
"module": "es2015",
"target": "es2015",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"moduleResolution": "node",
"jsx": "react",
"outDir": "build",
"rootDir": "src",
"baseUrl": "./",
"allowSyntheticDefaultImports": true,
"preserveConstEnums": true,
"sourceMap": true,
"skipLibCheck": true,
"types": ["react", "react-native", "jest"],
"paths": {
"@shared/*": [
"../shared/src/*"
]
}
},
"compileOnSave": false,
"exclude": ["android", "App.js", "ios", "build", "node_modules"],
"references": [{
"path": "../shared"
}]
}
./shared/tsconfig.json的内容
{
"compilerOptions": {
"module": "es2015",
"target": "es2015",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"rootDir": "src",
"outDir": "build",
"baseUrl": "src",
"composite": true,
"declaration": true,
"declarationMap": true,
},
"references": []
}
./client/src/app-load.tsx中使用的导入
import { isEmailValid } from "@shared/validation-utils";
运行时错误消息
无法从“build/app-load.js”解析“@shared/validation-utils”构建 JavaScript 包失败。
我也试过rootDir
用client/tsconfig.json
"include": [
"src/**/*",
"../shared/**/*"
],
就像在其他问题中看到的那样,仍然没有成功。
有谁知道我做错了什么?
解决方案
推荐阅读
- javascript - 如何在JS中的数组中加入连续的int元素
- javascript - 根据单选按钮选中状态保持 div 的活动状态
- javascript - 脚本在 div 外加载
- angular - 如何在 angular8 项目中打印 HTML 内容?
- video-streaming - 防止在流式传输期间下载视频
- python - 如何更改 Flask 中的路线?
- python-3.x - 如何使用请求 Python 从站点获得授权
- python-3.x - 用整数除浮点数
- android - ANDROID STUDIO 4.0 错误(开放阶段结束时没有进展)
- python - 在 Python 的 Pip 中,如何搜索与版本模式匹配的包的所有可能版本?