Skip to content

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

Closed

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.

Activity

  1. added
    Bugthing that needs fixing
    Needs Triageneeds review for next steps
    Release 7.xwork is associated with a specific npm 7 release
    on Mar 6, 2021
  2. FingalP commented on Mar 8, 2021

    @FingalP

    We had the same issue. The workaround works for now, thanks @waitem

  3. Fadoli commented on Mar 9, 2021

    @Fadoli

    Having the same issue here,

    an other workaround (if you don't want to modify all your publish config) is to modify line 51 of flat-options.js to

    cache: join(obj.cache || '~/.npm', '_cacache'),
    
  4. johnthad commented on Mar 12, 2021

    @johnthad

    We had the same issue. The workaround works for now, thanks @waitem

    This workaround does create a local directory ~ with the cache info (macOS 10.15.7).

  5. yellowtailfan commented on Mar 12, 2021

    @yellowtailfan

    I just encountered this bug, and the "cache": "~/.npm", work around caused a side-effect where the cache was written in the project folder (<project>/~/.npm) instead of my home directory. So I've reverted back to NPM 6.x instead. I'm using NPM in WSL2.

  6. stheine commented on Mar 15, 2021

    @stheine

    experienced the same in npm 7.6.3 and node v14.16.0. found a workaround by completely removing the publishConfig section from the package.json.

  7. lorenzogrv commented on Mar 15, 2021

    @lorenzogrv

    Hi everybody. I can confirm this issue too. Proposed workaround (adding publishConfig.cache) helped to step over, same side-effect as @yellowtailfan explains.

    In this particular case I can't remove publishConfig from package.json as it's need to publish against gitlab's package registry, as suggested by @stheine .

    Did not downgrade to 6.x to test.

    I'm glad to see the pull request over this comment. Keep up the good work.

    $ uname -srv
    Linux 5.4.0-66-generic #74~18.04.2-Ubuntu SMP Fri Feb 5 11:17:31 UTC 2021
    $ npm --version
    7.6.3
    $ node --version
    v12.21.0

    I suggest future readers "cache": "cache.npm" or the like so you don't accidentally try to rm -r ~ within your project, which may have fatal effects within your user's home

  8. lorenzogrv commented on Mar 15, 2021

    @lorenzogrv

    Hi again. Just noticed the workaround has another side-effect: It will publish with --tag set to undefined

    Well, it may not be the workaround at all, but side-effect is there

    Check npm show @scope/package-name to see if side-effect affects you. npm publish --tag latest works as expected, after the needed version bump.

  9. self-assigned this
    on Mar 15, 2021
  10. 150 remaining items

  11. Gauhar commented on Mar 31, 2021

    @Gauhar

    I can confirm that this issue was happening on my end as well on npm version 7.6.3 and node version v15.12.0. Since we I am publishing a public package then you can get rid of publishConfig

  12. yairEO commented on Apr 10, 2021

    @yairEO

    I also confirm this issue occurs as of right now, using npm version 7.9.0, node version v12.21.0

    I've removed the publishConfig property from the package.json file and now I am able to publish.

  13. added a commit that references this issue on Aug 24, 2021
  14. added a commit that references this issue on Nov 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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