3
votes

I'm attempting to build a few monorepo workspaces and publishing them to our organization's github packages.

I've set my publishConfig on each package to point to the owner like so:

"publishConfig": {
   "registry": "https://npm.pkg.github.com/"
},

And then ensured I'm logged into npm via npm login using my personal access token as the password.

I then push my changes, then run lerna publish for my package to go to github packages on the private registry of my organization, however I get a very vague 404 at the end:

lerna info Looking for changed packages since v0.0.5
? Select a new version (currently 0.0.5) Patch (0.0.6)

Changes:
 - @elementsoftworks/ui: 0.0.0 => 0.0.6

? Are you sure you want to publish these packages? Yes
lerna info execute Skipping releases
lerna info git Pushing tags...
lerna info publish Publishing packages to npm...
lerna info Verifying npm credentials
lerna http fetch GET 200 https://registry.npmjs.org/-/npm/v1/user 565ms
lerna http fetch GET 200 https://registry.npmjs.org/-/org/joemethven/package?format=cli 295ms
lerna WARN The logged-in user does not have any previously-published packages, skipping permission checks...
lerna info Checking two-factor auth mode
lerna http fetch GET 200 https://registry.npmjs.org/-/npm/v1/user 235ms
lerna http fetch PUT 404 https://npm.pkg.github.com/@elementsoftworks%2fui 590ms
lerna ERR! E404 The expected resource was not found.
josephmethven@Josephs-MBP @element-softworks-ui % 

Could anyone tell me what I'm doing wrong in this process?

lerna.json

{
  "packages": [
    "packages/*"
  ],
  "npmClient": "yarn",
  "useWorkspaces": true,
  "version": "0.0.3"
}

packages.json

{
  "name": "element-softworks-ui",
  "private": true,
  "version": "0.0.0",
  "main": "index.js",
  "license": "MIT",
  "workspaces": [
    "packages/*"
  ],
  "devDependencies": {
    "@babel/plugin-proposal-throw-expressions": "^7.10.1",
    "lerna": "^3.22.0"
  },
  "dependencies": {
    "@fortawesome/fontawesome-svg-core": "^1.2.28",
    "@fortawesome/react-fontawesome": "^0.1.9",
    "@popperjs/core": "^2.4.0",
    "@reach/router": "^1.3.3",
    "axios": "^0.19.2",
    "formik": "^2.1.4",
    "gatsby": "^2.22.12",
    "gatsby-link": "^2.4.3",
    "react": "^16.13.1",
    "react-dom": "^16.13.1",
    "react-popper": "^2.2.3",
    "yup": "^0.29.1"
  },
  "scripts": {
    "bootstrap": "lerna bootstrap --use-workspaces"
  }
}

Individual packages package.json

{
  "name": "@elementsoftworks/ui",
  "repository": {
    "url": "ssh://[email protected]:elementsoftworks/element-softworks-ui.git"
  },
  "module": "index.js",
  "version": "0.0.6",
  "main": "index.js",
  "license": "MIT",
  "dependencies": {
    "gatsby": "^2.22.12",
    "gatsby-link": "^2.4.3",
    "react": "^16.13.1",
    "react-dom": "^16.13.1"
  },
  "publishConfig": {
    "registry": "https://npm.pkg.github.com/"
  }
}

2

2 Answers

0
votes

This indicates you did not use a personal access token when you tried to login into npm.

lerna info Checking two-factor auth mode

You have to login with

$npm login....
username=<username>
password<your PAT token>
email=<email>

You can create .npmrc with content

//npm.pkg.github.com/:_authToken=<YOURTOKEN>

Documentation to create PAT TOKEN

0
votes

In my case, I was using a CI where I had no access to interactive login or things like that. Older packages were updated correctly, but new packages gave me a 404, so I thought it would be something related to the package itself, and it was.

I was missing two fields on the package's package.json, repository and publishConfig.

Adding these two fields, as below, it worked nicely. (note the expanded form of repository)

"repository": {
  "type": "git",
  "url": "ssh://[email protected]/__user__/__repo-name__.git",
  "directory": "packages/__new-package-name__"
},
"publishConfig": {
  "registry": "https://npm.pkg.github.com/"
}