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

NPM install -g failed execution of postinstall-xxxxxx.cmd #5474

Closed
PlanBernhard opened this issue Sep 6, 2022 · 4 comments
Closed

NPM install -g failed execution of postinstall-xxxxxx.cmd #5474

PlanBernhard opened this issue Sep 6, 2022 · 4 comments

Comments

@PlanBernhard
Copy link

PlanBernhard commented Sep 6, 2022

Issue

npm install -g electron results in this error

npm ERR! code 1
npm ERR! path C:\data\dev\dy\we\quick-start\node_modules\electron
npm ERR! command failed
npm ERR! command C:\WINDOWS\system32\cmd.exe /d /s /c C:\Users\X\AppData\Local\Temp\postinstall-a836babe.cmd
npm ERR! Blocked by group policy. Please contact your system administrator (translated).
npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\X\AppData\Local\npm-cache\_logs\2022-09-06T09_22_56_569Z-debug-0.log

Our company policies blocking the execution of cmd files from the appdata folder. Other modules like electron-cli did also fail with the same error message.

Tried solutions

Overrule the installation path by adding

prefix = 'C:\data\dev\npm-global'

into C:\Users\X\.npmrc file, but the error persits.
And installed NodeJS to C:\data\dev\NodeJS but this does still not solve the problem.

Questions

  1. What does postinstall-xxxxx.cmd ?
  2. Is it possible to configure a different location for postinstall-xxxxx.cmd?

EDIT 1

Ok, my bad. I just tried to install expressjs and had no such error. It seems like a problem related to electron, but I am not sure, because I don't work with NodeJS normally. If I am correct, please give me some feedback and I will close this issue.

@wraithgar
Copy link
Member

It looks like this is a limitation of your own operating system settings preventing you from running external scripts. This is not something npm can fix.

@axelheer
Copy link

The change using temporary script files was introduced with run-script:

npm/run-script#78

I'm not a node expert either, but it seems it's using %TEMP% without any possibility to configure this. But this is not a limitation and can be fixed! Not running any temporary script file, which any process wrote to the system wide temp directory, is a reasonable precaution, isn't it?

Workaround:

> $env:TEMP = '...' # path, where execution of scripts is allowed
> npm whatever

A config setting / argument switch to guide run-script into a "safe" directory would be nice, though.

@michha
Copy link

michha commented Oct 11, 2022

A workaround (but still not a permanent solution) would be editing the file C:\Program Files\nodejs\npm.cmd and adding a restricted change to the temp variable

:: Created by npm, please don't edit manually.
@ECHO OFF

SET TMP=C:\UnrestricedFolder\temp
SET TEMP=C:\UnrestricedFolder\temp

SETLOCAL

...

@wraithgar
In our company we use Microsoft AppLocker.
To reduce malware risk, a company can restrict the folders where scripts and programs can be executed. And one of the first folders are always the temp folders, because they are globally writeable so probably the first target.

@bryan-davis
Copy link

@wraithgar
Like @michha, my employer blocks scripts from running under %APPDATALOCAL% and provides us with a specific directory to be used instead. Other software provides the means of specifying which directory to use for temp scripts and it'd be great to have npm provide the same feature.

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

5 participants