Ich entwickle eine
React Native + TypeScript Bibliothek und installiere sie lokal in einem anderen Projekt mit einer .tgz -Datei. Die Bibliothek funktioniert
, wenn ich den Import manuell schreibe, aber
vscode schlägt ihn nicht mit CMD + vor. [/b] Um die Bibliothek zu erstellen.
Code: Select all
yarn add file:./my-library-v1.0.0.tgz
Ich habe auch versucht, es
ohne @File zu installieren, nur den Pfad direkt verwendet:
Code: Select all
yarn add ./my-library-v1.0.0.tgz
< /code>
< /li>
[*] Die Build -Ausgabestruktur sieht so aus:
lib/
├── commonjs/
│ ├── index.js
│ ├── components/
│ ├── constants/
│ ├── helpers/
│ ├── types/
├── module/
│ ├── index.js
│ ├── components/
│ ├── constants/
│ ├── helpers/
│ ├── types/
├── typescript/
├── commonjs/src/index.d.ts
├── module/src/index.d.ts
< /code>
< /li>
mein [b]package.json
[/b] Konfiguration:
Code: Select all
"main": "./lib/commonjs/index.js",
"module": "./lib/module/index.js",
"types": "./lib/typescript/commonjs/src/index.d.ts",
"exports": {
".": {
"import": {
"types": "./lib/typescript/module/src/index.d.ts",
"default": "./lib/module/index.js"
},
"require": {
"types": "./lib/typescript/commonjs/src/index.d.ts",
"default": "./lib/commonjs/index.js"
}
}
}
< /code>
< /li>
< /ul>
[b] ✅ Was funktioniert < /strong> < /h3>
Wenn ich den Import manuell schreibe, funktioniert alles fein: < /strong>
🚨 Was funktioniert nicht < /strong> < /h3>
VSCODE schlägt den Import mit CMD +. < /code> (Schnellfix) < /strong> nicht vor:
[code]react/jsx-no-undef
< /code>
< /li>
Es werden keine automatischen Importvorschläge angezeigt. Alles: < /strong>
rm -rf node_modules && yarn install
[*] Starten Sie den Typscript -Server in VSCODE [/b] (
→ "TS -Server neu starten").
[*]
Sicherstellen, dass Index.d.ts korrekt lokalisiert ist in lib/Typscript/CommonJS/src/src/index.d.ts . class = "Lang-Bash PrettyPrint-Override">
Code: Select all
yarn add my-library@file:./my-library-v1.0.0.tgz
Importieren direkt aus lib/Commonjs , um zu überprüfen, ob Exporte das Problem waren:
Code: Select all
import MyComponent from "my-library/lib/commonjs";
< /code>
→ [b] Dies funktioniert, aber es ist nicht der richtige Weg, um das Paket zu importieren. Fehlt mir etwas in package.json
oder tsconfig.build.json , um das VSCODE das Paket für Quick Fix zu erkennen ((
)? [/b]

Könnte dies ein Problem mit Garn hinzufügen: .tgz anstatt von NPM zu installieren?

Ich entwickle eine [b] React Native + TypeScript [/b] Bibliothek und installiere sie lokal in einem anderen Projekt mit einer .tgz -Datei. Die Bibliothek funktioniert [b], wenn ich den Import [/b] manuell schreibe, aber [b] vscode schlägt ihn nicht mit CMD + vor.[code]react-native-builder-bob[/code] [/b] Um die Bibliothek zu erstellen.[code]yarn add file:./my-library-v1.0.0.tgz
[/code]
Ich habe auch versucht, es [b] ohne @File [/b] zu installieren, nur den Pfad direkt verwendet:
[code]yarn add ./my-library-v1.0.0.tgz
< /code>
< /li>
[*] Die Build -Ausgabestruktur sieht so aus:
lib/
├── commonjs/
│ ├── index.js
│ ├── components/
│ ├── constants/
│ ├── helpers/
│ ├── types/
├── module/
│ ├── index.js
│ ├── components/
│ ├── constants/
│ ├── helpers/
│ ├── types/
├── typescript/
├── commonjs/src/index.d.ts
├── module/src/index.d.ts
< /code>
< /li>
mein [b]package.json[/code] [/b] Konfiguration:
[code]"main": "./lib/commonjs/index.js",
"module": "./lib/module/index.js",
"types": "./lib/typescript/commonjs/src/index.d.ts",
"exports": {
".": {
"import": {
"types": "./lib/typescript/module/src/index.d.ts",
"default": "./lib/module/index.js"
},
"require": {
"types": "./lib/typescript/commonjs/src/index.d.ts",
"default": "./lib/commonjs/index.js"
}
}
}
< /code>
< /li>
< /ul>
[b] ✅ Was funktioniert < /strong> < /h3>
Wenn ich den Import manuell schreibe, funktioniert alles fein: < /strong>
🚨 Was funktioniert nicht < /strong> < /h3>
VSCODE schlägt den Import mit CMD +. < /code> (Schnellfix) < /strong> nicht vor:
[code]react/jsx-no-undef
< /code>
< /li>
Es werden keine automatischen Importvorschläge angezeigt. Alles: < /strong>
rm -rf node_modules && yarn install
[/code]
[*] Starten Sie den Typscript -Server in VSCODE [/b] ([code]⇧ Shift + ⌘ Cmd + P[/code] → "TS -Server neu starten").
[*] [b] Sicherstellen, dass Index.d.ts korrekt lokalisiert ist [/b] in lib/Typscript/CommonJS/src/src/index.d.ts . class = "Lang-Bash PrettyPrint-Override">[code]yarn add my-library@file:./my-library-v1.0.0.tgz
[/code]
[b] [url=viewtopic.php?t=8986]Importieren[/url] direkt aus lib/Commonjs , um zu überprüfen, ob Exporte das Problem waren: [/b]
[code]import MyComponent from "my-library/lib/commonjs";
< /code>
→ [b] Dies funktioniert, aber es ist nicht der richtige Weg, um das Paket zu importieren. Fehlt mir etwas in package.json [/code] oder tsconfig.build.json , um das VSCODE das Paket für Quick Fix zu erkennen (([code]cmd + .[/code])? [/b]
🔹 Könnte dies ein Problem mit Garn hinzufügen: .tgz anstatt von NPM zu installieren? 🚀