I just published my Node.js/typescript package to the npm registry but I cannot install it from it, even though installing it locally works.
Output from local installation:
$ npm i -g .
added 1 package in 9s
Output when I try from the registry:
$ npm i iffinity -g
npm ERR! code 2
npm ERR! path /home/sotiris/.nvm/versions/node/v18.18.0/lib/node_modules/iffinity/node_modules/iffinity
npm ERR! command failed
npm ERR! command sh -c npm run bundle
npm ERR! > [email protected] bundle
npm ERR! > tsc && webpack --config webpack.config.js
npm ERR!
npm ERR! src/cli.ts(3,30): error TS7016: Could not find a declaration file for module 'yargs'. '/home/sotiris/.nvm/versions/node/v18.18.0/lib/node_modules/iffinity/node_modules/yargs/index.cjs' implicitly has an 'any' type.
npm ERR! Try `npm i --save-dev @types/yargs` if it exists or add a new declaration (.d.ts) file containing `declare module 'yargs';`
npm ERR! src/cli.ts(29,10): error TS7006: Parameter 'yargs' implicitly has an 'any' type.
npm ERR! src/cli.ts(55,16): error TS7006: Parameter '_' implicitly has an 'any' type.
npm ERR! src/cli.ts(60,10): error TS7006: Parameter 'yargs' implicitly has an 'any' type.
npm ERR! src/cli.ts(144,25): error TS7006: Parameter 'argv' implicitly has an 'any' type.
npm ERR! src/cli.ts(171,10): error TS7006: Parameter 'yargs' implicitly has an 'any' type.
npm ERR! src/cli.ts(199,25): error TS7006: Parameter 'argv' implicitly has an 'any' type.
npm ERR! src/cli.ts(207,16): error TS7006: Parameter 'argv' implicitly has an 'any' type.
npm ERR! src/core/models/Story.ts(1,17): error TS2307: Cannot find module 'ejs' or its corresponding type declarations.
npm ERR! src/core/models/Story.ts(5,24): error TS2307: Cannot find module 'html-entities' or its corresponding type declarations.
npm ERR! src/utils/checks.ts(116,19): error TS2503: Cannot find namespace 'cheerio'.
npm ERR! src/utils/checks.ts(151,50): error TS7006: Parameter '_' implicitly has an 'any' type.
npm ERR! src/utils/checks.ts(151,53): error TS7006: Parameter 'snippet' implicitly has an 'any' type.
npm ERR! src/utils/compiler.ts(9,19): error TS7016: Could not find a declaration file for module 'yargs'. '/home/sotiris/.nvm/versions/node/v18.18.0/lib/node_modules/iffinity/node_modules/yargs/index.cjs' implicitly has an 'any' type.
npm ERR! Try `npm i --save-dev @types/yargs` if it exists or add a new declaration (.d.ts) file containing `declare module 'yargs';`
npm ERR! src/utils/compiler.ts(89,47): error TS2532: Object is possibly 'undefined'.
npm ERR! src/utils/config.ts(4,19): error TS7016: Could not find a declaration file for module 'yargs'. '/home/sotiris/.nvm/versions/node/v18.18.0/lib/node_modules/iffinity/node_modules/yargs/index.cjs' implicitly has an 'any' type.
npm ERR! Try `npm i --save-dev @types/yargs` if it exists or add a new declaration (.d.ts) file containing `declare module 'yargs';`
npm ERR! src/utils/snippets.ts(5,22): error TS2503: Cannot find namespace 'cheerio'.
npm ERR! src/utils/tags.ts(7,22): error TS2503: Cannot find namespace 'cheerio'.
npm ERR! src/utils/tags.ts(40,22): error TS2503: Cannot find namespace 'cheerio'.
npm ERR! src/utils/viewer.ts(1,19): error TS7016: Could not find a declaration file for module 'yargs'. '/home/sotiris/.nvm/versions/node/v18.18.0/lib/node_modules/iffinity/node_modules/yargs/index.cjs' implicitly has an 'any' type.
npm ERR! Try `npm i --save-dev @types/yargs` if it exists or add a new declaration (.d.ts) file containing `declare module 'yargs';`
npm ERR! A complete log of this run can be found in: /home/sotiris/.npm/_logs/2023-10-15T18_00_56_044Z-debug-0.log
I have all of the types it mentions installed as dev dependencies. This is my package.json
file:
{
"name": "iffinity",
"repository": {
"type": "git",
"url": "https://github.com/zehanort/iffinity.git"
},
"version": "0.1.0-pre4",
"description": "A minimal IF engine with iffinite capabilities",
"main": "./dist/cli.js",
"engines": {
"node": ">=10"
},
"scripts": {
"install": "npm run bundle",
"build": "npm run bundle",
"start": "node dist/cli.js",
"bundle": "tsc && webpack --config webpack.config.js"
},
"bin": {
"ifc": "./dist/cli.js"
},
"keywords": [],
"author": "Sotiris Niarchos",
"license": "MIT",
"devDependencies": {
"@types/cheerio": "^0.22.32",
"@types/ejs": "^3.1.3",
"@types/jquery": "^3.5.20",
"@types/node": "^20.8.2",
"@types/yargs": "^17.0.26",
"ejs": "^3.1.9",
"expose-loader": "^4.1.0",
"html-entities": "^2.4.0",
"jquery": "^3.7.1",
"terser-webpack-plugin": "^5.3.9",
"typescript": "^5.2.2",
"webpack": "^5.88.2",
"webpack-cli": "^5.1.4"
},
"dependencies": {
"ansis": "^1.5.6",
"cheerio": "^1.0.0-rc.12",
"flexible-tree-printer": "^1.0.2",
"iffinity": "^0.1.0",
"npm": "^10.2.0",
"puppeteer": "^21.3.8",
"yargs": "^17.7.2"
}
}
And my tsconfig.json
file:
{
"include": ["src/**/*.ts"],
"exclude": ["node_modules", "dist"],
"compilerOptions": {
"target": "es2016" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
"lib": [
"es6",
"DOM"
] /* Specify a set of bundled library declaration files that describe the target runtime environment. */,
"types": ["node"],
"typeRoots": ["node_modules/@types"],
"module": "commonjs" /* Specify what module code is generated. */,
"moduleResolution": "node" /* Specify how TypeScript looks up a file from a given module specifier. */,
"rootDir": "src" /* Specify the root folder within your source files. */,
"resolveJsonModule": true /* Enable importing .json files. */,
"allowJs": true /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */,
"checkJs": true /* Enable error reporting in type-checked JavaScript files. */,
"outDir": "dist" /* Specify an output folder for all emitted files. */,
"esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */,
"forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
"strict": true /* Enable all strict type-checking options. */,
"declaration": true /* Generate .d.ts files from TypeScript and JavaScript files in your project. */,
"sourceMap": true /* Create source map files for emitted JavaScript files. */,
"noImplicitAny": true /* Enable error reporting for expressions and declarations with an implied 'any' type. */,
"skipLibCheck": true /* Skip type checking all .d.ts files. */
}
}
You can also view my whole repo here if you'd like.
I'm a newbie in TS/Node.js/npm publishing, so any help would be greatly appreciated.
You have
"install": "npm run bundle"
script which is run when you install the packageSo it's run when you are trying to
npm i -g ...
itRename this script and it'll work
Currently, as you can see on https://www.npmjs.com/package/iffinity?activeTab=code , your package is missing
dist
folder in it, that's the reason it won't runYou should include
./dist/**/*
,./dist
will include only a./dist
file