How to set a project's package.json to be able to install from local registry with verdaccio

3/25/2021

I am learning microservices with docker and kubernetes by simple project, now I am trying to use local registry installed as a docker container with helm. I published my package/library in my local registry (I am using verdaccio) and successfully installed it on my current project with command "npm install @mycompany/mylibs --registry=http://localhost:4873". My problem is when I am trying to deploy my project to kubernetes via skaffold, it fails to download the packages from package.json config file. I tried both setting up .npmrc file to project's root folder and default registry on verdaccio conf file but all fail. Is there anyone has encountered same problem as mine and how to fix it. Somebody help please. Thank you

This is my project structure :

MyProject
|-auth (this service has dependency to @mycompany/mylibs)
| |-src
| |-Dockerfile
| |-package.json
|
|-infra/kube
| |-auth-depl.yaml
| |-ingress-srv.yaml


MySharedLibrary
| |-src
| |-package.json

auth's package.json :

{
  "name": "auth",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "ts-node-dev src/index.ts",
    "test": "jest --watchAll --no-cache"
  },
  "jest": {
    "preset": "ts-jest",
    "testEnvironment": "node",
    "setupFilesAfterEnv": [
      "./src/test/setup.ts"
    ]
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@mycompany/mylibs": "^1.0.3",
    "@types/cookie-session": "^2.0.42",
    "@types/express": "^4.17.9",
    "@types/jsonwebtoken": "^8.5.0",
    "cookie-session": "^1.4.0",
    "express": "^4.17.1",
    "express-async-errors": "^3.1.1",
    "express-validator": "^6.7.0",
    "jsonwebtoken": "^8.5.1",
    "mariadb": "^2.5.1",
    "mysql2": "^2.2.5",
    "sequelize": "^6.3.5",
    "ts-node-dev": "^1.0.0",
    "typescript": "^4.1.2"
  },
  "devDependencies": {
    "@types/jest": "^26.0.19",
    "@types/supertest": "^2.0.10",
    "jest": "^26.6.3",
    "supertest": "^6.0.1",
    "ts-jest": "^26.4.4"
  }
}

I am using:

Windows 10 PC as main host for docker and where the project hosted.

docker version 19.03.13

npm version 6.14.6

verdaccio 4.12.0

helm 3.5.3

skaffold 1.13.0

The error message after I deploy my project with skaffold dev :

npm ERR! 404 Not Found - GET https://registry.npmjs.org/@mycompany%2fmylibs - Not found
npm ERR! 404
npm ERR! 404  '@mycompany/mylibs@^1.0.3' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404 It was specified as a dependency of 'app'
npm ERR! 404
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.

I want my deployment process each container could find all required dependencies on local registry (http://localhost:4873) and when it couldn't find them, it should try to reach public npm (https://registry.npmjs.org or npmjs.com).

-- nomib
kubernetes
local
npm
registry
verdaccio

2 Answers

3/25/2021

You need to associate the scope with your registry:

npm login --registry=http://localhost:4873 --scope=@mycompany

You can find the documenation here

After this npm install install package from you repository if the package is in the scope @mycompany

-- Troopers
Source: StackOverflow

4/2/2021

Thanks everyone for helping me, I solved this problem by reconfiguring my Dockerfile on auth service by adding line:

RUN npm config set registry http://<the_local_registry_container_IP>:4873

I am successful building the container but it raised new issues "request has been deprecated, see github.com/request/request/issues/3142" cause of I am using supertest. I don't know why I am still searching for the main problem. In another occasion if I build it with public npm repo, it doesn't raise that problem.

-- nomib
Source: StackOverflow