Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] npm link fails when running inside path with hash tag # #5120

Closed
2 tasks done
AgainPsychoX opened this issue Jul 3, 2022 · 1 comment · Fixed by #5122
Closed
2 tasks done

[BUG] npm link fails when running inside path with hash tag # #5120

AgainPsychoX opened this issue Jul 3, 2022 · 1 comment · Fixed by #5122
Labels
Bug thing that needs fixing Needs Triage needs review for next steps Release 8.x work is associated with a specific npm 8 release

Comments

@AgainPsychoX
Copy link
Contributor

Is there an existing issue for this?

  • I have searched the existing issues

This issue exists in the latest npm version

  • I am using the latest npm

Current Behavior

When working inside path that includes hash character (#), using npm link causes to crash because it cuts the path at the hash. My guess it's because it handles it as URI, just with file:// schema, and even those have # used as hash fragment.

Under Windows:

S:\#test>npm init
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.

See `npm help init` for definitive documentation on these fields
and exactly what they do.

Use `npm install <pkg>` afterwards to install a package and
save it as a dependency in the package.json file.

Press ^C at any time to quit.
package name: (#test) test-the-hash-for-npm-link
version: (1.0.0)
description:
entry point: (index.js)
test command:
git repository:
keywords:
author:
license: (ISC)
About to write to S:\#test\package.json:

{
  "name": "test-the-hash-for-npm-link",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
}


Is this OK? (yes)

S:\#test>ls
'ls' is not recognized as an internal or external command,
operable program or batch file.

S:\#test>dir
 Volume in drive S has no label.
 Volume Serial Number is 0E8F-6BAF

 Directory of S:\#test

03.07.2022  17:47    <DIR>          .
03.07.2022  17:47    <DIR>          ..
03.07.2022  17:47               222 package.json
               1 File(s)            222 bytes
               2 Dir(s)  53 127 081 984 bytes free

S:\#test>code package.json

S:\#test>npm link
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path S:\/package.json
npm ERR! errno -4058
npm ERR! enoent ENOENT: no such file or directory, open 'S:\package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\PsychoX\AppData\Local\npm-cache\_logs\2022-07-03T15_49_16_433Z-debug-0.log

S:\#test>

The complete log of npm link:

0 verbose cli C:\Program Files\nodejs\node.exe C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js
1 info using [email protected]
2 info using [email protected]
3 timing npm:load:whichnode Completed in 0ms
4 timing config:load:defaults Completed in 2ms
5 timing config:load:file:C:\Program Files\nvm\v16.13.1\node_modules\npm\npmrc Completed in 1ms
6 timing config:load:builtin Completed in 1ms
7 timing config:load:cli Completed in 2ms
8 timing config:load:env Completed in 0ms
9 timing config:load:file:S:\#test\.npmrc Completed in 1ms
10 timing config:load:project Completed in 2ms
11 timing config:load:file:C:\Users\PsychoX\.npmrc Completed in 1ms
12 timing config:load:user Completed in 1ms
13 timing config:load:file:C:\Program Files\nodejs\etc\npmrc Completed in 1ms
14 timing config:load:global Completed in 1ms
15 timing config:load:validate Completed in 0ms
16 timing config:load:credentials Completed in 1ms
17 timing config:load:setEnvs Completed in 1ms
18 timing config:load Completed in 11ms
19 timing npm:load:configload Completed in 12ms
20 timing npm:load:mkdirpcache Completed in 1ms
21 timing npm:load:mkdirplogs Completed in 1ms
22 verbose title npm link
23 verbose argv "link"
24 timing npm:load:setTitle Completed in 0ms
25 timing config:load:flatten Completed in 2ms
26 timing npm:load:display Completed in 4ms
27 verbose logfile logs-max:10 dir:C:\Users\PsychoX\AppData\Local\npm-cache\_logs
28 verbose logfile C:\Users\PsychoX\AppData\Local\npm-cache\_logs\2022-07-03T15_49_16_433Z-debug-0.log
29 timing npm:load:logFile Completed in 5ms
30 timing npm:load:timers Completed in 0ms
31 timing npm:load:configScope Completed in 0ms
32 timing npm:load Completed in 24ms
33 timing arborist:ctor Completed in 1ms
34 silly logfile start cleaning logs, removing 1 files
35 silly logfile done cleaning log files
36 timing idealTree:init Completed in 6ms
37 timing idealTree Completed in 8ms
38 timing command:link Completed in 24ms
39 verbose stack Error: ENOENT: no such file or directory, open 'S:\package.json'
40 verbose cwd S:\#test
41 verbose Windows_NT 10.0.19043
42 verbose node v16.13.1
43 verbose npm  v8.13.2
44 error code ENOENT
45 error syscall open
46 error path S:\/package.json
47 error errno -4058
48 error enoent ENOENT: no such file or directory, open 'S:\package.json'
49 error enoent This is related to npm not being able to find a file.
49 error enoent
50 verbose exit -4058
51 timing npm Completed in 142ms
52 verbose unfinished npm timer reify 1656863356547
53 verbose unfinished npm timer reify:loadTrees 1656863356558
54 verbose unfinished npm timer idealTree:userRequests 1656863356566
55 verbose code -4058
56 error A complete log of this run can be found in:
56 error     C:\Users\PsychoX\AppData\Local\npm-cache\_logs\2022-07-03T15_49_16_433Z-debug-0.log

Expected Behavior

Expected behaviour would be npm link just working as usual, creating link in global packages directory.

Steps To Reproduce

  1. Prepare empty folder in path (or name) including hash character (#).
  2. Initialize package with npm init.
  3. Try npm link (with admin privileges under Windows, as creating links sometimes requires those).

Environment

  • npm: 8.13.2
  • Node.js: v16.13.1
  • OS Name: Microsoft Windows 10 Home 10.0.19043 N/A Build 19043
  • System Model Name: GS65 Stealth 8SE
  • npm config:
; "user" config from C:\Users\PsychoX\.npmrc

//registry.npmjs.org/:_authToken = (protected)
prefix = "C:\\Program Files\\nodejs"

; node bin location = C:\Program Files\nodejs\node.exe
; node version = v16.13.1
; npm local prefix = D:\Projects\#gaming\StellarisCheats
; npm version = 8.13.2
; cwd = D:\Projects\#gaming\StellarisCheats
; HOME = C:\Users\PsychoX
; Run `npm config ls -l` to show all defaults.
@AgainPsychoX AgainPsychoX added Bug thing that needs fixing Needs Triage needs review for next steps Release 8.x work is associated with a specific npm 8 release labels Jul 3, 2022
@AgainPsychoX
Copy link
Contributor Author

AgainPsychoX commented Jul 3, 2022

Workarounds

A) There is workaround available for now: just avoid using using the hash character (#) in your path!

B) Link the package yourself (works only partially, the bin scripts are not created):

In my case on Windows using PowerShell that was:

New-Item -ItemType SymbolicLink -Path "$(npm root -g)\\$(node -p "require('./package.json').name")" -Target "$(Get-Location)"

On Linux it would be something along the lines of:

ln -s "$PWD" "$(npm root -g)/$(node -p 'require('\''./package.json'\'').name')"

(both of those require you to navigate next to your package.json of course, as npm link would)

AgainPsychoX added a commit to AgainPsychoX/Stellaris-Save-API that referenced this issue Jul 5, 2022
Note: Part of those are old uncommited changes from months ago, and some are recent. Cutting into separate commits was too troublesome.

+ List command also shows paths
+ Add `--overwrite` on pack command
+ Add `screenX/Y` proxy property for coords real `x`/`y`
+ Fleets/ships removing/adding
+ Galactic systems adding (untested)
+ Refactor game data loading (+ caching & variables)
+ Update `ts-node` loaders
+ Update README a bit
+ Update some dependencies
+ Investigate issue with `#` in path names for `npm link`, see npm/cli#5120
+ Multiple loggers and `--debug-except` (simple, debug only)
+ Fix many handles for game version 3.4, some still broken (like names)
+ Working `combat:fleets` command to test fleets composition
+ Other minor fixes and changes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing Needs Triage needs review for next steps Release 8.x work is associated with a specific npm 8 release
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant