NativeScript / NativeScript/nx

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

Offen
#64 2 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

answered question
Vorherrschende Sprache
TypeScript
Sterne
68
Forks
15
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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?

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne mit libs/nativescript-utils/src/index.ts und den plattformspezifischen Dateien und vergleiche anschließend die Bibliotheksdateien tsconfig.json und tsconfig.lib.json mit dem tsconfig.app.json der Apps. Reproduziere den Fehler, dass Dateien bei der TypeScript-Kompilierung fehlen, und verfolge, welche Konfiguration die Einbeziehung von Bibliotheksdateien steuert. Erledigt ist es, wenn sowohl die .ios.ts- als auch die .android.ts-Implementierung kompiliert werden, wenn sie aus der Bibliothek importiert werden.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
typescript
Bereich
build-system, tooling
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Ruhig
Klarheit
Muss geklärt werden
Anfängerfreundlichkeit
25/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.