Simple Fellow
Simple Fellow

Reputation: 4622

published npm package not installed as expected using verdaccio

my objective is to build and publish a package for commonly used typescript functions on verdaccio, an npm registry running on docker.

I build my typescript package. this is my project structure

enter image description here

package.json

    {
  "name": "communications",
  "version": "1.0.0",
  "description": "provides functional way of interacting with NATS",
  "main": "lib/index.js",
  "types": "lib/index.d.ts",
  "files": [
    "lib/**/*"
  ],
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "build": "tsc",
    "library": "tsc && npm unpublish --force --registry http://localhost:4873 && npm publish --registry http://localhost:4873"
  },
  "author": "bumblebee",
  "license": "ISC",
  "dependencies": {
    "nats": "^2.9.2"
  }
}

this is my tsconfig.json

{
  "compilerOptions": {
    /* Language and Environment */
    "target": "ES2016" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,

    /* Modules */
    "module": "CommonJS" /* Specify what module code is generated. */,
    /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */

    /* JavaScript Support */
    // "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. */
    // "maxNodeModuleJsDepth": 1,                        /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */

    /* Emit */
    "declaration": true /* Generate .d.ts files from TypeScript and JavaScript files in your project. */,
    "declarationMap": true /* Create sourcemaps for d.ts files. */,
    "outDir": "./lib" /* Specify an output folder for all emitted files. */,

    /* Interop Constraints */
    "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. */,

    /* Type Checking */
    "strict": true /* Enable all strict type-checking options. */,
    "noImplicitAny": true /* Enable error reporting for expressions and declarations with an implied 'any' type. */,
    "strictNullChecks": true /* When type checking, take into account 'null' and 'undefined'. */,
    "strictFunctionTypes": true /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */,
    "strictBindCallApply": true /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */,
    "strictPropertyInitialization": true /* Check for class properties that are declared but not set in the constructor. */,
    "noImplicitThis": true /* Enable error reporting when 'this' is given the type 'any'. */,
    "alwaysStrict": true /* Ensure 'use strict' is always emitted. */,
    "noUnusedLocals": true /* Enable error reporting when local variables aren't read. */,
    "noUnusedParameters": true /* Raise an error when a function parameter isn't read. */,
    "noUncheckedIndexedAccess": true /* Add 'undefined' to a type when accessed using an index. */,
    "noImplicitOverride": true /* Ensure overriding members in derived classes are marked with an override modifier. */,

    /* Completeness */
    "skipLibCheck": true /* Skip type checking all .d.ts files. */
  },
  "include": ["src"],
  "exclude": ["node_modules", "**/__tests__/*"]
}

this is my .npmignore

package-lock.json
node_modules/

this is the folder structure in my lib after running tsc

enter image description here

The project is successfully published in verdaccio. when I try to install it using

npm install communications --registry http://localhost:4873/ 

here is what I get

enter image description here

package.json is the only file I get. nothing else. off course this results in compilation errors even for importing anything.

Why is it that my lib folder is completely ignored and not pubslied in the npm package?

thats

Upvotes: 0

Views: 543

Answers (1)

Simple Fellow
Simple Fellow

Reputation: 4622

Everything I was doing was correct. I was not using the command

npm pack

which creates a compressed package communication.nats-1.0.0.tgz that was also published. only after that I was able to get all the required files. It was a silly mistake but the article I followed didn't mention this at all. the sequence should be as follows:

tsc
npm pack
npm publish --registry="path-to-custom-registry:port"

Upvotes: 1

Related Questions