Issue 1:
Current Behavior:

running npm publish get an error :

18 timing config:load Completed in 8ms
19 verbose npm-session 2c8eccb75d3455d8
20 timing npm:load Completed in 12ms
21 verbose publish [ '.' ]
22 timing command:publish Completed in 13ms
23 verbose stack TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined
23 verbose stack at new NodeError (node:internal/errors:329:5)
23 verbose stack at validateString (node:internal/validators:129:11)
23 verbose stack at join (node:path:1081:7)
23 verbose stack at flatten (/usr/lib/node_modules/npm/lib/utils/flat-options.js:50:10)
23 verbose stack at Publish.publishConfigToOpts (/usr/lib/node_modules/npm/lib/publish.js:140:12)
23 verbose stack at Publish.publish (/usr/lib/node_modules/npm/lib/publish.js:58:32)
24 verbose cwd /home/alban/dev/eda-vue-components
25 verbose Linux 4.19.104-microsoft-standard
26 verbose argv "/usr/bin/node" "/usr/sbin/npm" "publish" "."
27 verbose node v15.11.0
28 verbose npm v7.6.1
29 error code ERR_INVALID_ARG_TYPE
30 error The "path" argument must be of type string. Received undefined
31 verbose exit 1

Expected Behavior:

it should be a success

Steps To Reproduce:

remove any "cache" config

npm publish on a working project

Environment:

wsl archlinux

node v15.11.0

npm v7.6.1

workaround

adding "cache":"~/.npm" in package.json solves the problem.

fix

I guess list[0] here is supposed to be the default config... but for any reason is not resolved... but I may be wrong here.

I also notice https://github.com/npm/cli/blob/latest/lib/utils/flat-options.js#L50 is the only flatten option that is supposed not to be defined : maybe the problem is there ?

Might be related to this change (the code was cache: join(npm.config.get('cache'), '_cacache'), before, maybe get use default value if any ?

Issue 2:
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:

In this environment...

Ubuntu 20.04

Node 14.16.0

npm 7.6.1

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"
},

Run npm publish

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.