0

I have two npm libraries, stored in our company's gitlab package repository. Both libraries are separate gitlab projects with different ids. If i try to use them separately - everything is fine. But I can't use them both in, let's say, third project.

I found only one solution for similar problem here, but it didn't helped me.

My steps:

STEP 1

npm config set @my-reg/library-one-project-name:registry https://gitlab.some.url/gitlab/api/v4/projects/111111/packages/npm/
npm config set "//gitlab.some.url/gitlab/api/v4/projects/111111/packages/npm/:_authToken" "PROJECT_ONE_TOKEN"

npm config set @my-reg/library-two-project-name:registry https://gitlab.some.url/gitlab/api/v4/projects/222222/packages/npm/
npm config set "//gitlab.some.url/gitlab/api/v4/projects/222222/packages/npm/:_authToken" "PROJECT_TWO_TOKEN"

NPM registry file:

@my-reg/library-one-project-name:registry=https://gitlab.some.url/gitlab/api/v4/projects/111111/packages/npm/
//gitlab.some.url/gitlab/api/v4/projects/111111/packages/npm/:_authToken=PROJECT_ONE_TOKEN
@my-reg/library-two-project-name:registry=https://gitlab.some.url/gitlab/api/v4/projects/222222/packages/npm/
//gitlab.some.url/gitlab/api/v4/projects/222222/packages/npm/:_authToken=PROJECT_TWO_TOKEN

RESULT 1: npm tries to donwload packages from npmjs.org


STEP 2

npm config set @my-reg:registry https://gitlab.some.url/gitlab/api/v4/projects/111111/packages/npm/
npm config set "//gitlab.some.url/gitlab/api/v4/projects/222222/packages/npm/:_authToken" "PROJECT_ONE_TOKEN"

npm config set @my-reg:registry https://gitlab.some.url/gitlab/api/v4/projects/222222/packages/npm/
npm config set "//gitlab.some.url/gitlab/api/v4/projects/222222/packages/npm/:_authToken" "PROJECT_TWO_TOKEN"

NPM registry file:

https://gitlab.some.url/gitlab/api/v4/projects/111111/packages/npm/=
//gitlab.some.url/gitlab/api/v4/projects/111111/packages/npm/:_authToken=PROJECT_ONE_TOKEN
https://gitlab.some.url/gitlab/api/v4/projects/222222/packages/npm/=
//gitlab.some.url/gitlab/api/v4/projects/222222/packages/npm/:_authToken=PROJECT_TWO_TOKEN

RESULT 2: npm tries to donwload packages from npmjs.org


STEP 3

npm config set @my-scope:registry https://gitlab.some.url/gitlab/api/v4/projects/111111/packages/npm/
npm config set "//gitlab.some.url/gitlab/api/v4/projects/111111/packages/npm/:_authToken" "PROJECT_ONE_TOKEN"

npm config set @my-scope:registry https://gitlab.some.url/gitlab/api/v4/projects/222222/packages/npm/
npm config set "//gitlab.some.url/gitlab/api/v4/projects/222222/packages/npm/:_authToken" "PROJECT_TWO_TOKEN"

NPM registry file:

@my-scope:registry=https://gitlab.asseco.lt/gitlab/api/v4/projects/222222/packages/npm/
//gitlab.some.url/gitlab/api/v4/projects/111111/packages/npm/:_authToken=PROJECT_ONE_TOKEN
//gitlab.some.url/gitlab/api/v4/projects/222222/packages/npm/:_authToken=PROJECT_TWO_TOKEN

RESULT 3: npm downloads SECOND library from gitlab, but tries to donwload first package from npmjs.org

Thank you in advance.

1 Answer 1

1

The solution is to create token for the projects group in gitlab (not for single npm project), where libraries are stored and add this key to npm config for all packages from this registry. Here is how you can add multiple libraries from the same scope to project:

npm config set @my-scope:registry=https://gitlab.some.url/gitlab/api/v4/packages/npm/
npm config set "//gitlab.some.url/gitlab/api/v4/packages/npm/:_authToken=PROJECTS_GROUP_TOKEN"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.