I am working in a monorepo called my_monorepo that contains a project called my_project that I am trying to publish to Github Packages. The my_monorepo/my_project/package.json file currently looks like this:
{
"name": "@my_monorepo/package_name",
"version": "0.1.30",
"repository": {
"type": "git",
"url": "git+https://github.com/my_org/my_monorepo/my_project.git"
},
"publishConfig": {
"registry": "https://npm.pkg.github.com"
},
...
}
I have a package already published the package to AWS CodeArtifact and I want to publish it to Github Packages.
Within AWS CodeArtifact the package exists with a package name of package_name and namespace of my_monorepo. So it can be installed as @my_monorepo/package_name.
My workflow file looks like the below. I have temporarily set up the above to publish when I push changes, just while testing things out, but I intend on publishing on merge.
name: Publish Github Package
on:
pull_request:
paths:
- "my_project/**"
branches:
- master
defaults:
run:
working-directory: ./my_project
shell: bash
jobs:
publish-gpr:
name: Publish to Github Packages
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: my_project/.nvmrc
cache: "yarn"
cache-dependency-path: "my_project/yarn.lock"
registry-url: https://npm.pkg.github.com/
- run: yarn install --frozen-lockfile
- run: yarn build
- run: yarn publish
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
However it fails to publish and throws the following error on the yarn publish step:
error Couldn't publish package: "https://npm.pkg.github.com/@my_monorepo%2fpackage_name: Permission permission_denied: The requested installation does not exist."
Yet, I am able to successfully publish to Github Packages when I update the my_monorepo/my_project/package.json file to look like this:
{
"name": "@my_org/package_name",
"version": "0.1.30",
"repository": {
"type": "git",
"url": "git+https://github.com/my_org/my_monorepo/my_project.git"
},
"publishConfig": {
"registry": "https://npm.pkg.github.com"
},
...
}
i.e. the name has been updated from @my_monorepo/package_name to @my_org/package_name.
In this case, my package in AWS CodeArtifact is able to be installed as @my_monorepo/package_name, whereas my package in Github Packages is able to be installed as @my_org/package_name.
I'd like to use the same namespace, ideally my_monorepo, to install the package from whichever registry is specified.
Am I able to do this? If so, how?
No.
Unless you owned the account with the name of the scope you're using elsewhere, and had a PAT to publish the package to that account instead of the one you're running it in.