[question] How to use platform specific code in libs?

未关闭
#64 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
25/100
Issue 类型
缺陷
描述清晰度
需要澄清
活跃度
冷清
技术栈
typescript

调研方向

从 libs/nativescript-utils/src/index.ts 和平台特定文件开始,然后将库的 tsconfig.json 和 tsconfig.lib.json 与各 app 的 tsconfig.app.json 进行比较。重现 TypeScript 编译中缺少文件的错误,并追踪哪个配置控制库文件的包含。完成的标准是从库中导入时,.ios.ts 和 .android.ts 两个实现都能编译。

由索引模型根据 Issue 内容生成。

描述

answered question

It's me again :)

This time it's a question on how to do platform specific code in the libs. Here's my current issue:

I have these files under libs/nativescript-utils:

  • src/lib/nativescript-utils.d.ts
    • export function nativescriptUtils(): string;
  • src/lib/nativescript-utils.android.ts
  • src/lib/nativescript-utils.ios.ts
  • src/index.ts
    • export * from './lib/nativescript-utils';

Then I import the nativescriptUtils() in the app. When running the app I get this error:

ERROR in ../../libs/nativescript-utils/src/lib/nativescript-utils.ios.ts
Module build failed (from ../../node_modules/@ngtools/webpack/src/index.js):
Error: /Users/frank/git/private/nx-mobile-test/libs/nativescript-utils/src/lib/nativescript-utils.ios.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.
    at /Users/frank/git/private/nx-mobile-test/node_modules/@ngtools/webpack/src/ivy/loader.js:64:26
 @ ../../libs/nativescript-utils/src/index.ts 1:0-41 1:0-41
 @ ./src/features/home/components/home.component.ts 2:0-71 12:41-58
 @ ./src/features/home/home.module.ts 5:0-50
 @ ./src/app.routing.ts 15:28-65
 @ ./src/app.module.ts 3:0-49 10:89-105
 @ ./src/main.ts 6:0-41 11:69-78

I did the same exercise under apps, d.ts + ios.ts + android.ts + index.ts -> same issue -> solved it by adding "**/*.ios.ts" to includes in tsconfig.app.json. But no matter what I do in the libs and tsconfig.json or tsconfig.lib.json, it's not being picked up.

Do you have any tips on how to fix this?

主要语言
TypeScript
星标
68
派生
15
PR 合并指标
30 天内没有已合并 PR

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

NativeScript/nx 的其他 Issue

查看 NativeScript/nx 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。