laggingreflex / npm-link-better

18 stars 4 forks source link

nlc with npm-prefix no such file or directory #8

Closed keyoke closed 4 years ago

keyoke commented 4 years ago

Hi, This is a useful tool, I'm currently running into an issue with the tool around npm prefixes when running

nlc [linked package]

I get the following error-

Error: ENOENT: no such file or directory, stat 'C:\Users\VssAdministrator\AppData\Roaming\npm\node_modules[linked package]' npm ERR! code ELIFECYCLE npm ERR! errno 1

The link was successfully created

npm WARN [linked package]@1.0.0 No description npm WARN [linked package]@1.0.0 No repository field.

audited 84 packages in 0.838s

3 packages are looking for funding run npm fund for details

found 0 vulnerabilities

C:\npm\prefix\node_modules[linked package] -> D:\a\1\s\libs[linked package]

am running this on a build agent which seems to have a global prefix defined, , If I configure the same scenario on my local dev machine I get the same error.

Many Thanks Gareth

laggingreflex commented 4 years ago

Firstly, are you sure your [linked package] is actually npm-linked, i.e. have you run npm link from inside your [linked package]? Sorry for asking, I know you specifically wrote "linked", but just to be sure..

Second, have you set a custom prefix-path in your .npmrc? If so could you share your config? I faced a similar issue while doing just that, and I think it's probably a problem that needs to be addressed in https://github.com/jonschlinkert/global-modules/issues/13. Although in my case it was specifically about me using a tilde "~" in my path, which doesn't seem to be the cause in your case, but perhaps a similar problem of using some other form of custom path that also doesn't work with global-modules..?

And how about other commands: npm-link-save, and npm-link-quick, are those working as expected or are you getting the same error with them too?

keyoke commented 4 years ago

Thanks I missed the relationship between global-modules & global prefix libraries. Yes I'm definitely linking before calling nlc. In this scenario I'm using hosted build agents provided by Azure DevOps. In the past the npm config on agent images was setup with this script - https://github.com/microsoft/azure-pipelines-image-generation/blob/83eb28f760cb8ecd808eb9f6f740a854398ebb99/images/win/scripts/Installers/Install-NodeLts.ps1

$PrefixPath = 'C:\npm\prefix' $CachePath = 'C:\npm\cache'

New-Item -Path $PrefixPath -Force -ItemType Directory New-Item -Path $CachePath -Force -ItemType Directory

choco install nodejs-lts -y --force

Add-MachinePathItem $PrefixPath $env:Path = Get-MachinePath

setx NPM_CONFIG_PREFIX $PrefixPath /M $env:NPM_CONFIG_PREFIX = $PrefixPath

setx NPM_CONFIG_CACHE $CachePath /M $env:NPM_CONFIG_CACHE = $CachePath

npm config set registry http://registry.npmjs.org/

Thanks

laggingreflex commented 4 years ago

Ah, I see the problem. You're using the environment variable NPM_CONFIG_PREFIX to set the npm prefix-path. That's something that doesn't (yet) seem to be supported by the dependency I'm using to get the prefix path. It seems to have been discussed there though: https://github.com/jonschlinkert/global-prefix/pull/5#issuecomment-206824135.

Actually I notice it reads the env var PREFIX (just that, not the full NPM_CONFIG_PREFIX) here. Can you switch to using PREFIX instead? That might work.

Or I'll see if I can/should implement getting prefix-path on my own in this library itself. Simply getting it via npm config get prefix command ought to do it. It even seems to handle nicely my tilde ~ use case I mentioned above.

laggingreflex commented 4 years ago

Did just that https://github.com/laggingreflex/npm-link-better/commit/29dcbb4f4bfb4d6ef75b20e68cd760dafffc1126. Published v0.5.0

That should fix this. Please reopen if not.

keyoke commented 4 years ago

awsome will test

sahilrajput03 commented 4 years ago

This is a really good library, I use it regularly, its awesome!!!.