npm install -g git+... vs `git clone ... && cd ... && npm install -g .`


(Anthony Sottile) #1

I’m seeing an odd discrepancy in behaviour between the following commands. I’m using nodeenv to make isolated node environments, here’s my setup:

Installation via npm install -g .

commands:

type deactivate_node >& /dev/null && deactivate_node
rm -rf nenv && ~/opt/venv/bin/nodeenv nenv --prebuilt && . nenv/bin/activate
rm -rf cspell && git clone https://github.com/Jason3S/cspell
cd cspell
npm install -g .
cspell /dev/null

output:

$ type deactivate_node >& /dev/null && deactivate_node
$ rm -rf nenv && ~/opt/venv/bin/nodeenv nenv --prebuilt && . nenv/bin/activate
 * Install prebuilt node (11.10.0) ..... done.
$ rm -rf cspell && git clone https://github.com/Jason3S/cspell
Cloning into 'cspell'...
remote: Enumerating objects: 91, done.
remote: Counting objects: 100% (91/91), done.
remote: Compressing objects: 100% (64/64), done.
remote: Total 3060 (delta 47), reused 53 (delta 25), pack-reused 2969
Receiving objects: 100% (3060/3060), 3.43 MiB | 1.10 MiB/s, done.
Resolving deltas: 100% (2038/2038), done.
$ cd cspell
$ npm install -g .
/tmp/t/nenv/bin/cspell -> /tmp/t/nenv/lib/node_modules/cspell/bin.js
+ cspell@3.2.2
added 67 packages from 32 contributors in 5.61s
$ cspell /dev/null
internal/modules/cjs/loader.js:615
    throw err;
    ^

Error: Cannot find module './dist/app'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:613:15)
    at Function.Module._load (internal/modules/cjs/loader.js:539:25)
    at Module.require (internal/modules/cjs/loader.js:667:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at Object.<anonymous> (/tmp/t/cspell/bin.js:5:1)
    at Module._compile (internal/modules/cjs/loader.js:738:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:749:10)
    at Module.load (internal/modules/cjs/loader.js:630:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:570:12)
    at Function.Module._load (internal/modules/cjs/loader.js:562:3)

Installation via npm install git+...

For whatever reason, this works (?) though I expected it to do the same thing as cloning and installing manually.

Commands:

type deactivate_node >& /dev/null && deactivate_node
rm -rf nenv && ~/opt/venv/bin/nodeenv nenv --prebuilt && . nenv/bin/activate
npm install -g git+https://github.com/Jason3S/cspell
cspell /dev/null

Output:

$ type deactivate_node >& /dev/null && deactivate_node
$ rm -rf nenv && ~/opt/venv/bin/nodeenv nenv --prebuilt && . nenv/bin/activate
 * Install prebuilt node (11.10.0) ..... done.
$ npm install -g git+https://github.com/Jason3S/cspell
/tmp/t/cspell/nenv/bin/cspell -> /tmp/t/cspell/nenv/lib/node_modules/cspell/bin.js
+ cspell@3.2.2
added 67 packages from 32 contributors in 48.87s
$ cspell /dev/null
CSpell: Files checked: 1, Issues found: 0 in 0 files

:thinking:

I’m inclined to believe this is a bug, but I’ve tagged [support] for now since I might be missing something.


Have `npm install -g filesystem/path` run the same prepare / etc. pathway that `npm install -g git+...` does
(Anthony Sottile) #2

Seems I can work around this by using npm install -g git+file://$PWD but this seems like a glorious hack :(


(Lars Willighagen) #3

npm takes some extra steps when installing git dependencies, steps similar to what a developer usually does when publishing a package. This includes generating build files, which cspell seems to be missing here. The steps comes down to:

  • npm install --dev --prod --ignore-prepublish --no-progress --no-save
  • npm pack (which includes npm run prepare)

After which you can run

npm install -g cspell-1.0.0.tgz

If you instead actually want to link the directory you should also be able to run

  • npm link
  • and npm run prepare when you want any changes compiled to dist

npm install -g git+file://C:\Path\To\Repository does not work on windows
(Anthony Sottile) #4

Should npm install -g . do the same things? Seems odd that it doesn’t


(Anthony Sottile) #5

Also protip on github links, if you press [y] while on the page it’ll generate a permalink so you don’t have linkrot when linking to specific files / code chunks


(Lars Willighagen) #6

Oh, I must have forgotten this time. But I usually use the menu on the left, and [y] is much quicker, thanks!


(Anthony Sottile) #7

@larsgw should npm install -g . do the same steps? seems a surprising behaviour that it doesn’t


(Lars Willighagen) #8

It could, but npm install doesn’t prepare local directory deps, as you can do that with npm link.


(Anthony Sottile) #9

npm link doesn’t appear to work either:

$ rm -rf cspell && git clone https://github.com/Jason3S/cspell
$ npm link cspell
/tmp/t/nenv/bin/cspell -> /tmp/t/nenv/lib/node_modules/cspell/bin.js
+ cspell@3.2.2
added 67 packages from 32 contributors in 5.766s
/tmp/t/node_modules/cspell -> /tmp/t/nenv/lib/node_modules/cspell
$ cspell /dev/null
internal/modules/cjs/loader.js:615
    throw err;
    ^

Error: Cannot find module './dist/app'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:613:15)
    at Function.Module._load (internal/modules/cjs/loader.js:539:25)
    at Module.require (internal/modules/cjs/loader.js:667:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at Object.<anonymous> (/tmp/t/cspell/bin.js:5:1)
    at Module._compile (internal/modules/cjs/loader.js:738:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:749:10)
    at Module.load (internal/modules/cjs/loader.js:630:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:570:12)
    at Function.Module._load (internal/modules/cjs/loader.js:562:3)

(Lars Willighagen) #10

Sorry, forgot to make clear you’d have to run npm prepare at least once.


(Anthony Sottile) #11

Perhaps this is a proposal then:

when the argument to npm install -g is a filesystem location, perform the same normalization steps as would happen with npm install -g git+... – that is, don’t require / assume that a directory is already being developed on and set up.


(Lars Willighagen) #12

You can make an #ideas post for that! :slight_smile:


(Anthony Sottile) #13

Done – thanks for your quality support! :tada:

https://npm.community/t/have-npm-install-g-filesystem-path-run-the-same-prepare-etc-pathway-that-npm-install-g-git-does/5457/2


(system) closed #14

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.