Skip to content

[BUG] unable to publish when using publishConfig option - ERR_INVALID_ARG_TYPE #2834

@waitem

Description

@waitem

Current Behavior:

When running npm publish the following error appears:

npm ERR! code ERR_INVALID_ARG_TYPE
npm ERR! The "path" argument must be of type string. Received undefined

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/xx/.npm/_logs/2021-03-06T09_10_43_193Z-debug.log

The debug trace shows:

23 verbose stack TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined
23 verbose stack     at validateString (internal/validators.js:124:11)
23 verbose stack     at join (path.js:1039:7)
23 verbose stack     at flatten (/home/xx/.nvm/versions/node/v14.16.0/lib/node_modules/npm/lib/utils/flat-options.js:50:10)
23 verbose stack     at Publish.publishConfigToOpts (/home/xx/.nvm/versions/node/v14.16.0/lib/node_modules/npm/lib/publish.js:140:12)
23 verbose stack     at Publish.publish (/home/xx/.nvm/versions/node/v14.16.0/lib/node_modules/npm/lib/publish.js:58:32)

Expected Behavior:

npm publish to continue working as it did in version 6

Steps To Reproduce:

  1. In this environment...
    Ubuntu 20.04
    Node 14.16.0
    npm 7.6.1
  2. With this config...
    The package is configured to be published to github as per: github instrutions

package.json includes:

  "publishConfig": {
    "registry": "https://npm.pkg.github.com"
  },
  1. Run npm publish
  2. See error:
npm ERR! code ERR_INVALID_ARG_TYPE
npm ERR! The "path" argument must be of type string. Received undefined`

Environment:

Ubuntu 20.04
Node 14.16.0
npm 7.6.1

Possible cause

The issue seems to be related to changes made to the flatten() method in utils/flat-options.js
This is being called with the publishConfig which only contains a registry property.
However flatten (line 50), tries to use join() to create a path from the non-existent'cache property, hence the error (I believe).
Looking at the changes, it seems that v6 used to read the npm config for the cache value.

Workaround

My temporary workaround for this is to add a cache property to the publishConfig section, using the default cache value:

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

As others have noted, this workaround has the side-effect of creating a ~/.npm directory in the root of the project. My solution to this was then simply to add ~/.npm to .gitgnore

I guess that you could name this cache directory whatever you like. I used the default value simply to make publish work again. Note that my suggestion is purely a workaround and doesn't resolve the actual issue. Although I could see in the v7 code where the change has been made that is causing this issue, unfortunately I was unable to understand why that change was made.

Metadata

Metadata

Assignees

Labels

Bugthing that needs fixingRelease 7.xwork is associated with a specific npm 7 release

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions