Cli: [BUG] `npm run [command]` failed if the directory path contains colon

Created on 25 Dec 2019  路  5Comments  路  Source: npm/cli

What / Why

npm run [command] failed if the directory path contains colon
example: /path/to/project/appname:443/project

When

  • Whenever the project's directory path contains colon

Where

  • npm cli

How

Current Behavior

$ node -v
v12.13.1
$ npm -v
6.12.1

> appname@ dev /path/to/project/appname:443/project
> cross-env NODE_ENV=development webpack-dev-server --mode development

sh: cross-env: command not found
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT

Steps to Reproduce

add colon to the project's path

Expected Behavior

npm run [command] or npx [command] should work

Who

n/a

References

n/a

Bug

Most helpful comment

Actually it appears that colon is invalid in unix PATH variables according to the POSIX Standard. So this is impossible to fix. The only thing I can think of is perhaps npm run should include a relative path to the node_modules/.bin folder before it tries running the script.. so instead of doing a full absolute path, it could instead add ./node_modules/.bin to the PATH. This might have it's own set of issues though. Although I can't think of any right now.

All 5 comments

This also affects any project checked out of openSUSE Build Service as project hierchary is using : as separator. npm just adds the cwd to PATH without escaping

As per https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html#tag_08_03

Since is a separator in this context, directory names that might be used in PATH should not include a character.

So, it's not really possible to have : in PATH on POSIX systems... maybe a better solution would be to use relative paths instead of absolute when appending PATH

It鈥檚 better not to put colons in the path.

Can you escape the : in order to make this work?

Actually it appears that colon is invalid in unix PATH variables according to the POSIX Standard. So this is impossible to fix. The only thing I can think of is perhaps npm run should include a relative path to the node_modules/.bin folder before it tries running the script.. so instead of doing a full absolute path, it could instead add ./node_modules/.bin to the PATH. This might have it's own set of issues though. Although I can't think of any right now.

Was this page helpful?
0 / 5 - 0 ratings