VSCODE Quick Fix (`cmd + .`), der meine Bibliothek nicht vorschlägt, wenn er von` .tgz` installiert ist
Posted: 03 Mar 2025, 00:32
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.
Ich habe auch versucht, es ohne @File zu installieren, nur den Pfad direkt verwendet:
[/b] Konfiguration:
[*] 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">
Importieren direkt aus lib/Commonjs , um zu überprüfen, ob Exporte das Problem waren:
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? 
Code: Select all
react-native-builder-bob
Code: Select all
yarn add file:./my-library-v1.0.0.tgz
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
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
Code: Select all
⇧ Shift + ⌘ Cmd + P
[*] 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
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
Code: Select all
cmd + .