npm Community Forum (Archive)

The npm community forum has been discontinued.

To discuss usage of npm, visit the GitHub Support Community.

Incorrect folder name for npm link gives unhelpful error

What I Wanted to Do

I was trying to do npm link to a local repo but mistyped the folder name. I would expect a sensible error message saying the folder doesn’t exist.

What Happened Instead

I got a useless error message that said “Error: Argument #2: Expected array but got string” and “This is an error with npm itself:”

Reproduction Steps

mkdir foo
cd foo
npm init -y
npm link ../bar

Details

0 info it worked if it ends with ok
1 verbose cli [ 'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli   'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli   'link',
1 verbose cli   '../bar' ]
2 info using npm@6.4.1
3 info using node@v8.12.0
4 verbose npm-session 2018c2eb8d5786f3
5 verbose stack Error: Argument #2: Expected array but got string
5 verbose stack     at EventEmitter.install (C:\Users\David\AppData\Roaming\nvm\v8.12.0\node_modules\npm\lib\install.js:190:3)
5 verbose stack     at Object.commandCache.(anonymous function) (C:\Users\David\AppData\Roaming\nvm\v8.12.0\node_modules\npm\lib\npm.js:159:13)
5 verbose stack     at C:\Users\David\AppData\Roaming\nvm\v8.12.0\node_modules\npm\lib\link.js:93:24
5 verbose stack     at C:\Users\David\AppData\Roaming\nvm\v8.12.0\node_modules\npm\node_modules\graceful-fs\polyfills.js:284:29
5 verbose stack     at FSReqWrap.oncomplete (fs.js:152:21)
6 verbose cwd C:\dev\npm-test
7 verbose Windows_NT 10.0.17134
8 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "link" "../bar"
9 verbose node v8.12.0
10 verbose npm  v6.4.1
11 error code EINVALIDTYPE
12 error typeerror Error: Argument #2: Expected array but got string
12 error typeerror     at EventEmitter.install (C:\Users\David\AppData\Roaming\nvm\v8.12.0\node_modules\npm\lib\install.js:190:3)
12 error typeerror     at Object.commandCache.(anonymous function) (C:\Users\David\AppData\Roaming\nvm\v8.12.0\node_modules\npm\lib\npm.js:159:13)
12 error typeerror     at C:\Users\David\AppData\Roaming\nvm\v8.12.0\node_modules\npm\lib\link.js:93:24
12 error typeerror     at C:\Users\David\AppData\Roaming\nvm\v8.12.0\node_modules\npm\node_modules\graceful-fs\polyfills.js:284:29
12 error typeerror     at FSReqWrap.oncomplete (fs.js:152:21)
13 error typeerror This is an error with npm itself. Please report this error at:
13 error typeerror     <https://npm.community>
14 verbose exit [ 1, true ]

Platform Info

$ npm --versions
{ 'npm-test': '1.0.0',
  npm: '6.4.1',
  ares: '1.10.1-DEV',
  cldr: '32.0',
  http_parser: '2.8.0',
  icu: '60.1',
  modules: '57',
  napi: '3',
  nghttp2: '1.32.0',
  node: '8.12.0',
  openssl: '1.0.2p',
  tz: '2017c',
  unicode: '10.0',
  uv: '1.19.2',
  v8: '6.2.414.66',
  zlib: '1.2.11' }
$ node -p process.platform
win32


Hello, I want to take a look

Can you give me any guidance? @zkat :slight_smile:


@alopezsanchez I don’t know how detailed of a guide you want (or need), but npm link code is in lib/link.js, and the code (here, don’t click if you want to find it yourself) should go:

link -> linkInstall -> linkPkg

but instead goes

link -> linkInstall -> npm.commands.install

because the file doesn’t exist.


@larsgw thanks!!!

One question. I can easily add a er.code !== 'ENOENT' condition in https://github.com/npm/cli/blob/59e5056a2129cb2951f4ff3b657ada20657f01a7/lib/link.js#L92
but… do you think this is the right way to solve this? I mean, are there more errors that should go to linkPkg?


I think that even with only ENOENT there would be false positives. We want to distinguish between existing folders, non-existing folders, and certain packages. Both non-existing folders and packages would give an error. Maybe checking if it’s supposed to be a package the same way Node.js does, by requiring it to start with /, ./ or ../? @zkat thoughts?


that’s hella clever. /cc @iarna to see if Too Clever™.


@larsgw @zkat Is this still available to take up :thinking: Can you guide me on this :smiley: