简体   繁体   中英

I try publish a package to npm but I take this error every time. Why?

I try publish a package to npm but I take this error every time.

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/garax/.npm/_logs/2021-03-19T14_44_29_986Z-debug.log

2021-03-19T14_44_29_986Z-debug.log:

0 verbose cli [ '/usr/bin/node', '/usr/bin/npm', 'publish' ]
1 info using npm@7.6.3
2 info using node@v15.12.0
3 timing config:load:defaults Completed in 2ms
4 timing config:load:file:/usr/lib/node_modules/npm/npmrc Completed in 0ms
5 timing config:load:builtin Completed in 0ms
6 timing config:load:cli Completed in 2ms
7 timing config:load:env Completed in 0ms
8 timing config:load:file:/home/garax/Documents/cryptme/.npmrc Completed in 0ms
9 timing config:load:project Completed in 1ms
10 timing config:load:file:/home/garax/.npmrc Completed in 1ms
11 timing config:load:user Completed in 1ms
12 timing config:load:file:/usr/etc/npmrc Completed in 0ms
13 timing config:load:global Completed in 0ms
14 timing config:load:cafile Completed in 0ms
15 timing config:load:validate Completed in 1ms
16 timing config:load:setUserAgent Completed in 0ms
17 timing config:load:setEnvs Completed in 1ms
18 timing config:load Completed in 8ms
19 verbose npm-session 5177b76d17bb3059
20 timing npm:load Completed in 16ms
21 verbose publish [ '.' ]
22 timing command:publish Completed in 20ms
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/garax/Documents/cryptme
25 verbose Linux 5.11.2-arch1-1
26 verbose argv "/usr/bin/node" "/usr/bin/npm" "publish"
27 verbose node v15.12.0
28 verbose npm  v7.6.3
29 error code ERR_INVALID_ARG_TYPE
30 error The "path" argument must be of type string. Received undefined
31 verbose exit 1

All paths are string in my code.

Npm version: 7.6.3 Nodejs version: 15.12.0

The solution for this issue is to first add "cache": "~/.npm" under publishConfig object in package.json file. Later, add ~/.npm in .gitignore file. And now you will be able to npm publish easily without any error.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM