Azure App Service node deployment with patch-package module - azure-web-app-service

I am trying to run patch-package during a Node app deployment on Azure App Services (deployed with continuous integration from BitBucket). The patch-package script works fine locally (on Mac), but fails on Azure (Windows). The patch-package module is installed in node_modules but the post-install script fails with the following error:
Command: "D:\home\site\deployments\tools\deploy.cmd" Handling node.js
deployment. Creating app_offline.htm KuduSync.NET from:
'D:\home\site\repository' to: 'D:\home\site\wwwroot' Deleting
app_offline.htm Looking for app.js/server.js under site root. Using
start-up script app.js Generated web.config. The package.json file
does not specify node.js engine version constraints. The node.js
application will run with the default node.js version 14.16.0.
Selected npm version 6.14.11
my-app#1.0.0 postinstall D:\home\site\wwwroot patch-package
'patch-package' is not recognized as an internal or external command,
operable program or batch file. npm ERR! code ELIFECYCLE npm ERR!
errno 1 npm ERR! rs-email-yelp#1.0.0 postinstall: patch-package npm
ERR! Exit status 1
And here is my (simplified) package.json file:
{
"name": "my-app",
"version": "1.0.0",
"description": "",
"main": "app.js",
"private": true,
"dependencies": {
...
"patch-package": "^6.4.4",
...
},
"scripts": {
"postinstall": "patch-package"
}
}
I get the same error when I try and manually run npm i in Kudu command line.

In case anyone else has this issue, here is what solved it for me:
-stopped the web app
-deleted the node_modules folder
-ran a new deploy from git repo (which reinstalled all modules)
Everything back to normal.

In case someone else comes across this with the same issue I had...
I had added patch-package in devDependencies, but Azure is running npm i --production so patch-package never got installed.
Changing patch-package to be in dependencies fixed it for me.

Related

When using npm, commands fail due to cache access restriction/lock (errno EBUSY -4082)

Problem
I've been running into what appears to be a directory access issue in Windows when attempting to use npm. Having tried numerous suggestions from various other SO questions and answers, I thought I'd see if anyone might have suggestions or solutions based on log the output.
I'm continuously running into the error anytime I attempt an npm operation, including install (global or local), uninstall, update, or executing tools such as electron-packager as shown in the package.json scripts section, below the error itself.
Information
Operating system: Windows 10 (Build 19043)
node version: v18.3.0
npm version: 8.12.1
The error output itself is typically
:
npm ERR! code EBUSY
npm ERR! syscall rename
npm ERR! path C:\Users\<username>\AppData\Local\npm-cache\_cacache\tmp\a870f111
npm ERR! dest C:\Users\<username>\AppData\Local\npm-cache\_cacache\content-v2\sha512\d3\23\a585f82ed54ccfe948a39da16e212d9b112d87f43f74100e4e56c7f688e670ed506b8e7b57284c0a7c268503abcc5569023fcaa73f00b1c4f7670d5c2537
npm ERR! errno -4082
npm ERR! EBUSY: resource busy or locked, rename 'C:\Users\<username>\AppData\Local\npm-cache\_cacache\tmp\a870f111' -> 'C:\Users\<username>\AppData\Local\npm-cache\_cacache\content-v2\sha512\d3\23\a585f82ed54ccfe948a39da16e212d9b112d87f43f74100e4e56c7f688e670ed506b8e7b57284c0a7c268503abcc5569023fcaa73f00b1c4f7670d5c2537'
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\<username>\AppData\Local\npm-cache\_logs\2022-06-04T18_34_40_792Z-debug-0.log
Full log output: PasteBin
package.json
{
"name": "MyElectronApp",
"productName": "MyElectronApp",
"desktopName": "MyElectronApp",
"version": "1.0.0",
"description": "Foobar",
"main": "app.js",
"repository": "https://github.com/",
"keywords": [],
"author": "cognophile",
"license": "GNU General Public License v3.0",
"files": [
"app.js",
"assets/styles.css",
"resources/icon.png",
"resources/icon.ico",
"resources/icon.icns"
],
"scripts": {
"start": "npx electron .",
"build": "npm run build:macos && npm run build:linux && npm run build:windows",
"build:macos": "npx electron-packager . --overwrite --asar --out=dist --ignore='^media$' --prune --platform=darwin --arch=x64 --icon=resources/icon.icns --app-bundle-id=com.cognophile.myelectronapp --app-version=$npm_package_version && cd dist/MyElectronApp-darwin-x64 && zip -ryXq9 ../MyElectronApp-macos-${npm_package_version}.zip MyElectronApp.app",
"build:linux": "npx electron-packager . --overwrite --out=dist --ignore='^media$' --prune --platform=linux --arch=x64 --icon=resources/icon.png --app-bundle-id=com.cognophile.myelectronapp --app-version=$npm_package_version && cd dist/MyElectronApp-linux-x64/ && zip -ryq9 ../MyElectronApp-linux-${npm_package_version}.zip *",
"build:windows": "npx electron-packager . --overwrite --asar --out=dist --ignore='^media$' --prune --platform=win32 --arch=ia32 --icon=resources/icon.ico --version-string.ProductName=$npm_package_productName --app-version=$npm_package_version && cd dist/MyElectronApp-win32-ia32 && zip -ryq9 ../MyElectronApp-windows-${npm_package_version}.zip *"
},
"devDependencies": {
"electron": "^13.6.6",
"electron-builder": "^22.4.1",
"electron-packager": "^14.2.1"
},
"dependencies": {
"about-window": "^1.15.2"
}
}
Trying to run the scripts results in the same error, with differing details. For example, trying to execute the npm start script. The same is true for npm run build:windows, but the unfetchable package URL in the error is https://registry.npmjs.org/electron-packager
❯ npm start
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
> MyElectronApp#1.0.0 start
> npx electron .
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
npm ERR! code EBUSY
npm ERR! syscall rename
npm ERR! path C:\Users\<username>\AppData\Local\npm-cache\_cacache\tmp\01286790
npm ERR! dest C:\Users\<username>\AppData\Local\npm-cache\_cacache\content-v2\sha512\1b\71\c52f6c1e74e5c3c22e0f872bae840fa8e460c356b5c1f807c437a1f8cad2b7bfeb884bb387cbd8012a08d5deaa4b1395f5d4d1cfbc00cfd1b4f5c5e201e3
npm ERR! errno EBUSY
npm ERR! Invalid response body while trying to fetch https://registry.npmjs.org/electron: EBUSY: resource busy or locked, rename 'C:\Users\<username>\AppData\Local\npm-cache\_cacache\tmp\01286790' -> 'C:\Users\<username>\AppData\Local\npm-cache\_cacache\content-v2\sha512\1b\71\c52f6c1e74e5c3c22e0f872bae840fa8e460c356b5c1f807c437a1f8cad2b7bfeb884bb387cbd8012a08d5deaa4b1395f5d4d1cfbc00cfd1b4f5c5e201e3'
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\<username>\AppData\Local\npm-cache\_logs\2022-06-04T19_08_01_775Z-debug-0.log
Attempted solutions
I've tried a number of suggestions from a variety of sources, including (npm ERR! code ENOENT npm ERR! syscall rename [StackOverflow]):
Clearing the cache with npm cache clean --force then reinstalling (npm install)
Verifying the cache with npm cache verify then reinstralling (npm install)
Removing node_modules and package-lock.json, clearing the cache, and reinstalling
Removing read-only checkbox from project folder and cache folder (right-click > properties) which seems to immediately get reset
I've tried these in dedicated PowerShell terminals (non-admin and admin), and the integrated terminal in Visual Studio Code, all having the same result. I've also tried:
Repairing the nodejs installation via the installer
Uninstalling nodejs and removing node/npm related files and directories, restarting the PC, and reinstalling nodejs and attempting npm install in a fresh PowerShell terminal
Rebooting to ensure no other processes are using these directories (such as vscode or another terminal instance)
Closing anti-virus program (not attempted a full uninstall) and trying the above solutions
I suspect this relates to permissions on the cache directories, judging by the error message, but since it is npm which creates those directories after the npm cache clean, I'm not sure I understand what more is needed, and am naturally hesitant to change directory permissions (e.g. NodeJS change file and folder permissions [StackOverflow]) until having received advice.
Thanks in advance!

Git Error -4058 while trying to npm install nw-builder

I just created a new folder on my Desktop and loaded it to VSCode so I can start building/learning about NW.js. The first thing I've done was to open VSCode Terminal and execute npm init -y, then I've proceeded to run npm install nw#sdk. No error whatsoever.
Now my new folder has a package.json, a package-lock.json, and node_modules folder.
package.json content:
{
"name": "rename-merra-app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"nw": "^0.62.1-sdk"
}
}
When I try to run npm install nw-builder --save-dev as the reference suggests # https://www.npmjs.com/package/nw-builder, I got the following error:
npm ERR! code ENOENT
npm ERR! syscall spawn git
npm ERR! path git
npm ERR! errno -4058
npm ERR! enoent An unknown git error occurred
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Misharin\AppData\Local\npm-cache\_logs\2022-03-23T03_41_13_504Z-debug-0.log
The .log file can be found here: https://pastebin.com/cZAmugRF
I've tried the following:
Restart VSCode
Restart My Computer
Run npm install (Up to date, 120 packages, version 8.5.5)
Run npm outside VSCode, directly on the prompt (same error)
Delete package-lock.json
Reinstall NodeJS (17.8.0)
Install an older version of NodeJS (17.7.1)
Search for node.js running in the background (there is none)
Disable Windows Security
Run npm cache clear --force
Does anyone have any idea how to solve this error?
Maybe one of the git links (https://registry.npmjs.org/nw-builder) from the nw-builder package is down/offline? In that case, is there any way around it so I can start building with nw.js?
Thank you for your help!
Make sure you have Git installed:
https://git-scm.com
You'll likely want to change your code to:
"devDependencies": {
"nw": "0.62.1-sdk"
}
The ^ can download the normal version if it was published after the sdk version.
I haven't used nw-builder, but from my understanding, it hasn't received any updates in several years. There is a GitHub issue related to this:
https://github.com/nwjs-community/nw-builder/issues/530
Finally, here are instructions for how to manually create your own build:
https://gitlab.com/TheJaredWilcurt/battery-app-workshop
More tutorials are at:
https://nwutils.io

`npm publish` and `npm install` fail depending on `.npmrc` syntax used

Current Behavior:
I am attempting to configure a project to install dependencies from NPM. I will be publishing the project to GitHub Packages as a private package. If I use this syntax in my project's .npmrc:
#my-org:registry=https://npm.pkg.github.com/
I can install dependencies from NPM using npm install on my local machine. However, I cannot publish to GitHub Packages using npm publish. NPM informs me that I'm not authenticated. If I use this syntax in my project's .npmrc:
registry=https://npm.pkg.github.com/my-org/
I can publish using npm publish, but I cannot install dependencies with npm install. NPM informs me that it's trying to install dependencies from GitHub Packages, rather than NPM.
Expected Behavior:
Based on my reading, both syntaxes should be compatible with npm install and npm publish. However, it appears I can only use one or the other, based on my intended use.
Steps To Reproduce:
Install Node v15.7.0 and NPM 7.4.3 via nvm.
Log in to GitHub Packages with the command:
npm login --scope=#my-org --registry=https://npm.pkg.github.com
Check our ~/.npmrc file in our home folder. It should read:
#my-org:registry=https://npm.pkg.github.com/
//npm.pkg.github.com/:_authToken=<auth-token-used-for-login>
Create project with the following package.json:
{
"name": "#my-org/my-package",
"description": "A test.",
"version": "1.0.0",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "https://github.com/my-org/my-package.git"
},
"keywords": ["example"],
"author": "Me",
"license": "ISC",
"bugs": {
"url": "https://github.com/my-org/my-package/issues"
},
"homepage": "https://github.com/my-org/my-package",
"dependencies": {
"bootstrap": "^4.5.2"
}
}
Add the following .npmrc to our project:
#my-org:registry=https://npm.pkg.github.com/
Run npm install. Installation should succeed.
Run npm publish. Receive the following error:
npm ERR! code ENEEDAUTH
npm ERR! need auth This command requires you to be logged in.
npm ERR! need auth You need to authorize this machine using `npm adduser`
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/my-user/.npm/_logs/2021-01-28T20_19_55_974Z-debug.log
Change the project .npmrc to:
registry=https://npm.pkg.github.com/my-org/
Run npm publish. Publishing should succeed.
rm -rf node_modules/ package-lock.json in project.
Run npm install. Receive following error:
npm ERR! code E401
npm ERR! Incorrect or missing password.
npm ERR! If you were trying to login, change your password, create an
npm ERR! authentication token or enable two-factor authentication then
npm ERR! that means you likely typed your password in incorrectly.
npm ERR! Please try again, or recover your password at:
npm ERR! https://www.npmjs.com/forgot
npm ERR!
npm ERR! If you were doing some other operation then your saved credentials are
npm ERR! probably out of date. To correct this please try logging in again with:
npm ERR! npm login
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/my-user/.npm/_logs/2021-01-28T20_38_20_711Z-debug.log
Environment:
OS:
MacOS Catalina 10.15.7
MacOS Big Sur 11.1
Node: 15.7.0
npm: 7.4.3
Things I've tried
Using publishConfig
Unfortunately, publishConfig doesn't fix the issue. It also doesn't address that the two .npmrc syntaxes produce different results.
Project .npmrc authToken
NPM's documentation states there is no need to include the authToken in the project .npmrc. Authenticating with npm login and storing the authToken in the global ~/.npmrc should be sufficient.
Workaround
Using the --registry command line flag
I've found a workaround until the NPM bug affecting this issue is resolved. When using the following project .npmrc syntax:
#my-org:registry=https://npm.pkg.github.com/
If I run npm publish --registry=https://npm.pkg.github.com/, I can publish successfully. In addition, I can install dependencies without issue.
Update (May 30, 2021)
This has been fixed in NPM 7.5.3 and above.
Original answer (April 20, 2021)
This has been confirmed as a bug on NPM 7.x. The team is currently working to fix the bug with their GitHub Pull Request #2602. Until this bug fix has been released, the best recommendation is to do one of the workarounds listed below.
Workaround 1: --registry command line flag
When running npm publish, add the --registry flag. This flag enables developers to specify the registry they're aiming to publish to, overriding .npmrc or package.json configurations. For the example listed in my question, the project .npmrc should contain:
#my-org:registry=https://npm.pkg.github.com/
Publishing will succeed when initiated by running:
npm publish --registry=https://npm.pkg.github.com/
Workaround 2: Dummy token for default registry
According to npm developer wraithgar's comment on this bug's GitHub issue, you can use a dummy token for the default NPM registry to workaround this issue. In our project's .npmrc, add the following line:
//registry.npmjs.org/:_authToken=dummy
The full project .npmrc should contain:
//registry.npmjs.org/:_authToken=dummy
#my-org:registry=https://npm.pkg.github.com/
In the question, neither of the project .npmrc syntax's we've tried to use has designated a registry, because NPM's documentation states we don't have to. The documentation states that it'll check our global ~/.npmrc if there isn't one in our project .npmrc. The bug in NPM is causing NPM to check if a project .npmrc has designated a registry before it'll attempt to authenticate. In wraithgar's own words:
What happens is that currently the cli is only looking for your configured "registry" setting when seeing if you have logged in. So the temporary solution is either to override that setting (as you were doing by passing --registry), OR to add a token for the default (npm) registry so that the check for a token does not fail. The check is only looking for the presence of a token in the config, it's not validating it (that of course will happen when and if it is used during an actual request), so putting a dummy value in will stop the error until that PR lands.
After adding the dummy token, running npm publish and npm install should both succeed.
I had the same error. First thing I have fixed was npm version to > 7.5.3 as suggested in accepted answer, but no luck, same error:
npm ERR! code ENEEDAUTH
npm ERR! need auth This command requires you to be logged in.
npm ERR! need auth You need to authorize this machine using `npm adduser`
After trying all of advised workarounds it still was giving the same output. Finally I found the reason: I forgot to add the scope in the package.json "name" property, so problem was solved by changing
{
"name": "my-package",
...
to
{
"name": "#my-org/my-package",
...
I found 2 problems in steps from 1 to 7.
in step 4, did you try to add the field below in the package.json
"publishConfig": {
"registry": "https://npm.pkg.github.com/"
}
in .npmrc in step 5, I didn't see //npm.pkg.github.com/:_authToken=<auth-token-used-for-login>, remember // is not the comment. ; or # are for comments. https://docs.npmjs.com/cli/v6/configuring-npm/npmrc#comments

npm ERR! enoent ENOENT: no such file or directory, open 'C:\Users\...\package.json'

I'm doing a tutorial on VueJS. I am completely new to this, so not enitrely sure what I am doing.
I followed all instructions, installed all packages, here is the check I made in terminal in VSCode:
PS C:\Users\...\Documents\Vue - Getting Started> node --version
v12.18.0
PS C:\Users\...\Documents\Vue - Getting Started> npm --version
6.14.5
PS C:\Users\...\Documents\Vue - Getting Started> vue --version
#vue/cli 4.4.1
However, whenever I try to npm run serve as it's shown in the tutorial, it shows an error stating that a package.json is missing:
npm ERR! enoent ENOENT: no such file or directory, open 'C:\Users\...\package.json'
I checked, and indeed, I don't have a file called package.json in my user folder. I only have a file called package-lock.json.
I also noticed, that on the tutorial video, the terminal has something like 1: node, while in mine, I can see 1: powershell. Here is the screenshot:
screenshot from terminal
What am I missing? Thank you
As suggested by El, I did npm init and created a package.json file in my project folder. Inside, I added the bit suggested by El. The whole package.json file now looks like this:
{
"name": "package.json",
"version": "1.0.0",
"description": "package json",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"serve": "node index.js"
},
"author": "",
"license": "ISC"
}
And I am now getting this error:
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! package.json#1.0.0 serve: `node index.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the package.json#1.0.0 serve script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?
I think there's no need to explain Nodejs ENOENT error with such a self-explanatory error message: no such file or directory which simply means index.js or any file that you want to run with npm or node isn't in the current directory.
First you need to check to see if you are in the root of your project then in the root of your project you need to have a config file that is package.json for JavaScript(Nodejs, react, typescript and so on) projects.
So for making that config file you can use npm init command and it will ask you predefined questions about your projects.
for starting or serving your project you must have a script tag like this in your package.json file:
'scripts':{
'serve': 'node index.js',
}
then you can use npm run serve command in the root of your project to run serve command of your package.json file.
In case of VueJS, which I am not familiar with, I think you have a index.html file in the root directory of your project and aslo as I know you have vue installed on your machine. I guess you need to replace node index.js with following command to serve your Vue application:
'scripts':{
'serve': 'vue index.html',
}
and run npm run serve.
I fixed this problem with those commands:
// Locate to the folder, where the "node_modules" directory is stored
rm node_modules
npm i
deleted the project folder and then creating vue project
vue create my-project
This is how it worked for me

Error deploying node js restify application to heroku

I'm having an issue deploying a restify application to Heroku.
npm ERR! dtrace-provider#0.0.9 install: `node-waf clean ; node-waf configure build`
npm ERR! `sh "-c" "node-waf clean ; node-waf configure build"` failed with 1
npm ERR!
npm ERR! Failed at the dtrace-provider#0.0.9 install script.
npm ERR! This is most likely a problem with the dtrace-provider package,
npm ERR! not with npm itself.
It seems as if Heroku has an issue with dtrace, which restify makes use of, although doesn't require, I've read that you can bypass this by removing dtrace from restify's package.json file, however I have attempted this with no success.
I'm new to node and using Heroku and git so I'm sure there's something I'm missing, restify's package.json file contains the following:
"dependencies": {
"dtrace-provider": "0.0.9",
},
"optionalDependencies": {
"dtrace-provider": "0.0.9"
},
I have removed these lines but still receive the same error message as above after committing to git and pushing to Heroku.
Can anyone see what I'm missing?
When you deploy your application on heroku it installs the dependencies based on your application package.json file so it does not matter if you remove it from restify's package.json file because heroku picks the restify's package.json file from it's repository not from your repository. So, you need to find out how to resolve this error.

Resources