Extension build fails on dotnet run after switching git branch

I am running 16.2.0-rc2. I was testing something on a git branch but decided to go a different direction. I discarded all of the changes switched back to my master branch, but now when I run dotnet run on my master branch I get the error:

The command "npm run build" exited with code 127.

If I run npm run build in the extension everything is fine.

I tried dotnet clean and dotnet build but I can’t get the error to go away. I did comment out the npm run build in the ext.csproj file so I can keep working.

Hey @Spleeding1

Is there any other error in the console? There’s usually something before the exit code that helps explain where the error came from.

Have you also tried deleting the node_modules folder in case a dependency has been left over from the switch?

Hi @Spleeding1

Could you please try below steps to fix this issue?

1. Clear your local artifacts

Sometimes the old branch leaves behind node_modules or build output that conflicts. Try:

dotnet clean
dotnet restore

Then also clar npm cache/output:

cd path/to/extension
rm -rf node_modules
npm install

2. Verify .csproj targets

Open your extension .csproj — look for something like:

<Target Name="NpmBuild" BeforeTargets="Build">
  <Exec Command="npm run build" WorkingDirectory="$(ProjectDir)" />
</Target>

  • Make sure WorkingDirectory is set to where your package.json lives.

  • If it’s wrong (e.g. pointing to a folder you deleted on that branch), MSBuild will throw error 127.

3. Environment path issue

Sometimes when dotnet run calls npm, it doesn’t have the right PATH. Check:

where npm   # Windows
which npm   # macOS/Linux

If dotnet run can’t see it but your shell can, try adding:

<Exec Command="npm run build" WorkingDirectory="$(ProjectDir)" EnvironmentVariables="PATH=$(PATH)" />

4. Temporary workaround

You already did the right thing commenting out the npm run build in .csproj. That’s safe while developing. Another option is to make it conditional:

<Target Name="NpmBuild" BeforeTargets="Build" Condition=" '$(Configuration)' == 'Release' ">
  <Exec Command="npm run build" WorkingDirectory="$(ProjectDir)" />
</Target>

That way, it only runs for release builds, not every dotnet run.

@Rockerby I came back to this today and uncommented the extenstion package in the project .csproj, and now everything seems to be working. I wish I could diagnose this further, but I can’t. Thanks for your help, I will come back to these if I run into this issue again. As far as I can remember, there were no other errors.

1 Like