node.js - `Kan inte hitta modul` från en ny ägd TypeScript-modul
Jag har precis publicerat ett nytt Typescript-projekt på NPM-registret, puppeteer-jquery. Koden fungerar bra. Men när jag försöker använda det i ett annat projekt:
npm install puppeteer-jquery
och försök att importera det med:
import { PageEx, BrowserEx } from 'puppeteer-jquery';
Jag får felet: Kan inte hitta modulen 'puppeteer-jquery'.ts(2307)
Lokalt kan jag bara använda det genom att installera en lokal kopia av källkoden och importera:
import { PageEx, BrowserEx } from './node_modules/puppeteer-jquery/src/setup';
package.json från pupeteer-jquery:
{
"name": "puppeteer-jquery",
...
"main": "lib/index.js", /* also tried with "./lib/index.js" value */
"typings": "lib/index.d.ts", /* tried with "types" and "typings" key */
"devDependencies": {
...
"typescript": "^3.6.4"
},
"files": ["lib", "data/*.js"] /* data contains jquery.js as a ressource */
}
tsconfig.json från puppeteer-jquery:
{
"compilerOptions": {
"target": "ES2017",
"module": "commonjs",
"declaration": true,
"strict": true,
"moduleResolution": "node",
"esModuleInterop": true,
"outDir": "lib",
"rootDirs": [
"src"
]
},
"include": [ "src" ], /* added after the first post */
"exclude": ["node_modules", "lib"]
}
npm publish --dry-run:
npm notice 📦 [email
npm notice === Tarball Contents ===
npm notice 1.1kB LICENSE
npm notice 410B lib/index.js
npm notice 280.4kB data/jquery-3.4.1.js
npm notice 5.7kB lib/jQueryPlugin.js
npm notice 77B lib/PJQuery.js
npm notice 1.0kB lib/setup.js
npm notice 1.2kB package.json
npm notice 2.0kB README.md
npm notice 242B lib/index.d.ts
npm notice 411B lib/jQueryPlugin.d.ts
npm notice 2.2kB lib/PJQuery.d.ts
npm notice 518B lib/setup.d.ts
npm notice === Tarball Details ===
Detta problem liknar stackoverflow 54695891 men det är inte samma.
PS :
- detta är inte mitt första Typescript-projekt
- det här projektet har inga beroenden
- Jag försöker också inkludera TS-källkod och källkartor i det släppta paketet, men utan större framgång.
Svar #1
Jag laddade ner modulen och det ser ut som ett problem med din bygg- eller publiceringsinställning--filen lib/index.d.ts som typings pekar på finns inte i den publicerade versionen.
├── LICENSE
├── README.md
├── data
│ └── jquery-3.4.1.js
├── lib
│ ├── src
│ │ ├── PJQuery.d.ts
│ │ ├── PJQuery.js
│ │ ├── index.d.ts
│ │ ├── index.js
│ │ ├── jQueryPlugin.d.ts
│ │ ├── jQueryPlugin.js
│ │ ├── setup.d.ts
│ │ └── setup.js
│ └── test
│ ├── basic.spec.d.ts
│ └── basic.spec.js
└── package.json
