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

Adding yarn install path to %PATH% #1

Open
Tehnix opened this issue May 2, 2018 · 2 comments
Open

Adding yarn install path to %PATH% #1

Tehnix opened this issue May 2, 2018 · 2 comments

Comments

@Tehnix
Copy link

Tehnix commented May 2, 2018

For some reason, out of nowhere App Services stopped finding my npm executables, meaning that yarn could not be located.

The error will manifest itself something like,

...
remote: Verifying Yarn Install.
remote: D:\local\AppData\npm\yarn -> D:\local\AppData\npm\node_modules\yarn\bin\yarn.js
remote: D:\local\AppData\npm\yarnpkg -> D:\local\AppData\npm\node_modules\yarn\bin\yarn.js
remote: + yarn@1.6.0
remote: updated 1 package in 2.114s
remote: Installing Yarn Packages.
remote: yarn install v1.6.0
remote: [1/5] Validating package.json...
remote: [2/5] Resolving packages...
remote: success Already up-to-date.
remote: $ yarn run build
remote: 'yarn' is not recognized as an internal or external command,
remote: operable program or batch file.
remote: info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
remote: error Command failed with exit code 1.
remote: Failed exitCode=1, command=D:\local\AppData\npm\yarn install --production
remote: An error has occurred during web site deployment.
remote:
remote: Error - Changes committed to remote repository but deployment to website failed.
To https://xxxxxx.scm.azurewebsites.net:443/xxxxxx.git
   d7de8b7..8d52910  master -> master

My fix was to add the path to NPM executables to the batch PATH environmental variable.

SET PATH=%PATH%;D:\local\AppData\npm

so it now looks like this,

:: 3. Install Yarn
echo Verifying Yarn Install.
call :ExecuteCmd !NPM_CMD! install yarn -g
SET PATH=%PATH%;D:\local\AppData\npm

:: 4. Install Yarn packages
echo Installing Yarn Packages.
IF EXIST "%DEPLOYMENT_TARGET%\package.json" (
  pushd "%DEPLOYMENT_TARGET%"
  call :ExecuteCmd yarn install --production
  IF !ERRORLEVEL! NEQ 0 goto error
  popd
)

I don't know if other's are experiencing this issue, but if they are, I hope this leads them here. I am not 100% sure if the path will stay the same in every scenario, or it needs to be set in a more dynamic way, else you should be able to use this small addition in these scripts.

@aweber1
Copy link

aweber1 commented May 11, 2018

I ran into this same problem yesterday. Unfortunately didn't see this issue in the repo or could've saved myself a few hours of troubleshooting :)

Anyways, came to the same conclusion that the PATH should also be set. I used the following snippet to set it in a more "dynamic" way:

FOR /F "tokens=* USEBACKQ" %%F IN (`npm config get prefix`) DO (
SET "PATH=%PATH%;%%F"
)

Basically, it calls npm config get prefix which should report the install location for npm packages. Then store that value in the PATH variable.

Final version:

:: 3. Install Yarn
echo Verifying Yarn Install.
call :ExecuteCmd !NPM_CMD! install yarn -g
FOR /F "tokens=* USEBACKQ" %%F IN (`npm config get prefix`) DO (
SET "PATH=%PATH%;%%F"
)
IF !ERRORLEVEL! NEQ 0 goto error```

@tony-gutierrez
Copy link

Does this not result in the PATH constantly being made longer?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants