3

I have problem with my powershell script. I want to build one project which is based on node 10.17.0 and copy the result into other project which is based on node 8.11.4 and run the project.

   cd $PathToWebLibs

   Write-Host "..........Switching to node v10.17.0.........." -ForegroundColor Magenta
   nvm use 10.17.0

   Write-Host "..........Building WebLibs.........." -ForegroundColor Magenta
   npm run build_lib

   Write-Host "..........Copying files from ($PathToWebLibs\dist\rsp\core-ui) to ($PathToSFP\node_modules\@rsp) .........." -ForegroundColor Magenta

   cp -Recurse -Force ($PathToWebLibs + "\dist\rsp\core-ui") ($PathToSFP + "\node_modules\@rsp")

   cd $PathToSFP

   Write-Host "..........Switching to node v8.11.4.........." -ForegroundColor Magenta
   nvm use 8.11.4


   Write-Host "..........Starting SFP.........." -ForegroundColor Magenta
   npm run start

The problem is that when nvm changes version of node npm is not recognized. When I did it manually simply type in commands one by one it works.

I can just add that system environmental path is set correctly. I checked it. enter image description here

2
  • Does this answer your question? 'npm' is not recognized as internal or external command, operable program or batch file Commented Mar 25, 2020 at 11:29
  • @Theo yes, I did this, but for me it isn't work. The problem is not with npm but with powershell I think. When I run simple script like only change node by nvm and then run "npm -v" and i run this script in powershell it isn't work. When I do it manually and run it one by one, everything is ok. Commented Mar 25, 2020 at 12:03

2 Answers 2

1

nvm is designed to be run in-process by your shell, which is only supported for POSIX-compatible shells such as bash, and not for PowerShell:

nvm works on any POSIX-compliant shell (sh, dash, ksh, zsh, bash), in particular on these platforms: unix, macOS, and windows WSL.

On Unix-like platforms and possibly WSL, consider Node.js version manager n as an alternative, which doesn't rely on modifying the current shell's environment.

  • n-install allows installation of n directly from GitHub; for instance:
    curl -L https://git.io/n-install | bash
  • However, this particular installation method, which includes installation of Node.js itself, currently requires additional configuration in PowerShell (in your PowerShell $PROFILE file or, alternatively via persistent environment-variable definitions in the registry on Windows): $HOME/n/bin must be added to $env:Path, and $env:PREFIX must be set to $HOME/n (adjust the paths for WSL accordingly, if you're running PowerShell from outside WSL).
Sign up to request clarification or add additional context in comments.

Comments

0

I solved this problem using powershell Start-Sleep method after nvm use XXX. It helped and it works well currently.

2 Comments

Could you add more instructions on how to do this?!
I found 30 seconds to be sufficient. Did not test to see if something smaller would work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.