I seem to be having an issue running nodemon from node_modules in a deployed instance.
I have roughly this in my package.json
{
...
"version": "0.0.3",
"main": "dist/src/server.js",
"description": "Persistence Layer",
"engines": {
"node": "~6.7"
},
"scripts": {
"start": "nodemon",
},
"dependencies": {
...
"nodemon": "^1.11.0",
...
}
}
I have the following in my nodemon.json file
{
"restartable": "rs",
"verbose": true,
"debug": 5858,
"delay": 1,
"watch": [
"dist/",
"node_modules/"
],
"ext": "js",
"args": [
"--debug=5858",
"--max_old_space_size=6384",
"--optimize_for_size",
"--max_executable_size=6384",
"--stack_size=6384"
]
}
When i try npm run start i get the following:
jrlil#28178a64e860:/app# npm run start
npm info it worked if it ends with ok
npm info using npm#3.10.8
npm info using node#v6.9.1
npm info lifecycle api#0.0.3~prestart: api#0.0.3
npm info lifecycle api#0.0.3~start: api#0.0.3
> api#0.0.3 start /app
> nodemon
sh: 1: nodemon: Permission denied
npm info lifecycle -api#0.0.3~start: Failed to exec start script
npm ERR! Linux 3.10.0-514.16.1.el7.x86_64
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "start"
npm ERR! node v6.9.1
npm ERR! npm v3.10.8
npm ERR! code ELIFECYCLE
npm ERR! -api#0.0.3 start: `nodemon`
npm ERR! Exit status 126
npm ERR!
npm ERR! Failed at the -api#0.0.3 start script 'nodemon'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
However, when i run it using the following everything works as expected.
$node node_modules/nodemon/bin/nodemon.js
[nodemon] 1.12.1...
Why isn't npm run able to look into my node_modules folder and start nodemon?
This is actually more of a Linux question than a Node question, as it's a permissions issue -- the script nodemon being ran by npm does not have the right permissions.
If you use npm run start to invoke nodemon and you have the right permissions (e.g. root), npm will "hand off" the execution to nodemon and in the process possibly change the user to one without root permissions to be safe:
From the docs:
If npm was invoked with root privileges, then it will change the uid
to the user account or uid specified by the user config, which
defaults to nobody. Set the unsafe-perm flag to run scripts with root
privileges.
If you run node_modules/nodemon/bin/nodemon.js yourself (and you have root permissions), it bypasses that "hand off" so that nodemon.js is run with root permissions.
The most correct way to deploy a node application is to use something like pm2 to manage processes, and not use nodemon since nodemon is mostly used to watch for changes and restart the server (which is mostly only useful in development contexts). If you still want to use nodemon, you can combine it with the forever package with nodemon like explained here.
Related
package.json not found at root level of repository.
Cyclic runs scripts defined "scripts" section to build, test and run your app.
But my project is set up like:
-final
--backend
---package.json(including npm start)
--frontend
---package.json(including npm start)
-package.json
^ includes:
"scripts": {
"frontend": "cd frontend; npm start",
"backend": "cd backend; npm start"
How do I merge these packages together and put them into the root directory so I can make this react application live?
I was thinking about something like this:
"scripts": {
"frontend": "cd frontend; npm start",
"backend": "cd backend; npm start"
but when I go to the root directory (final)
npm ERR! Missing script: "start"
npm ERR!
npm ERR! Did you mean one of these?
npm ERR! npm star # Mark your favorite packages
npm ERR! npm stars # View packages marked as favorites
npm ERR!
npm ERR! To see a list of scripts, run:
npm ERR! npm run
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!
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
I'm setting up a local server, and I am running my server with npm run json:server but I am getting the following error:
npm ERR! Failed at the jsonserver#1.0.0 json:server script 'json-server --watch db.json'.
Can't figure out how to fix this?
I tried to update npm update -g and it doesn't help.
Also tried npm i -g npm
and install the json server locally using npm i --save-dev json-server
Doesn't help
Lenovo-ideapad-990-95IKB:~/Desktop/jsonserver$ **npm run json:server**
> jsonserver#1.0.0 json:server /home/zack/Desktop/jsonserver
> **json-server --watch db.json**
Could not find an option or flag "-c".
Usage: pub <command> [arguments]
Global options:
-h, --help Print this usage information.
--version Print pub version.
--[no-]trace Print debugging information when an error occurs.
--verbosity Control output verbosity.
[all] Show all output including internal tracing messages.
[error] Show only errors.
[io] Also show IO operations.
[normal] Show errors, warnings, and user messages.
[solver] Show steps during version resolution.
[warning] Show only errors and warnings.
-v, --verbose Shortcut for "--verbosity=all".
Available commands:
cache Work with the system cache.
deps Print package dependencies.
downgrade Downgrade the current package's dependencies to oldest versions.
get Get the current package's dependencies.
global Work with global packages.
help Display help information for pub.
publish Publish the current package to pub.dartlang.org.
run Run an executable from a package.
upgrade Upgrade the current package's dependencies to latest versions.
uploader Manage uploaders for a package on pub.dartlang.org.
version Print pub version.
Run "pub help <command>" for more information about a command.
See http://dartlang.org/tools/pub for detailed documentation.
npm ERR! Linux 4.19.5-041905-generic
npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "run" "json:server"
npm ERR! node v8.10.0
npm ERR! npm v3.5.2
npm ERR! code ELIFECYCLE
npm ERR! jsonserver#1.0.0 json:server: `json-server --watch db.json`
npm ERR! **Exit status 64**
npm ERR!
npm ERR! **Failed at the jsonserver#1.0.0 json:server script 'json-server --watch db.json'.**
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the jsonserver package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! json-server --watch db.json
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs jsonserver
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls jsonserver
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /home/zack/Desktop/jsonserver/npm-debug.log```
Here is package.json:
{
"name": "jsonserver",
"version": "1.0.0",
"description": "REST API Tracker",
"main": "index.js",
"scripts": {
"json:server": "json-server --watch db.json"
},
"author": "",
"license": "ISC",
"dependencies": {
"json-server": "^0.14.2"
}
}
Expected to start server on localhost:3000
Thank you for help!
I think the issue is you're merging the idea of an npm run script with starting a json-server and haven't fully implemented either aspect. Here are the steps I would try, assuming you wish to have a run script to start your json-server:
Rename db.json to package.json since this is actually your package.json file for your node project. You probably created this file when you ran npm init. This file is not the json data that you're mocking for the json-server when you start the server with your custom script command.
Create a new file called db.json and give it the mocked json you wish to use for your json-server. For example, from the documentation:
db.json:
{
"posts": [
{ "id": 1, "title": "json-server", "author": "typicode" }
],
"comments": [
{ "id": 1, "body": "some comment", "postId": 1 }
],
"profile": { "name": "typicode" }
}
Now change your custom run script command to not include special characters. For example, within your package.json change the following:
"scripts": {
"json:server": "json-server --watch db.json"
},
to:
"scripts": {
"start": "json-server --watch db.json"
},
Now start your server with your custom script command: npm run start. At this point there shouldn't be any errors for starting the server.
Now if you go to http://localhost:3000/posts/1, you should get the following json response:
{ "id": 1, "title": "json-server", "author": "typicode" }
Node.js projects are no longer working. Have node.js 7.10.x npm 4.2.1
Projects that were working are no longer working. I uninstalled node.js, removed npm-cache, reinstalled fresh. Deleted node_modules directory, ran npm install on project's package.json and npm start xxxx etc. No matter what project I run, the error remains the same as shown below. The same projects installed on Linux Ubuntu work just fine.
No clue as to why these projects are no longer working. The following error is consistent with each node project I've tested.
Any help would be appreciated. Thanks in advance.
npm ERR! Windows_NT 10.0.14393
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "test"
npm ERR! node v7.10.1
npm ERR! npm v4.2.0
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! muber#1.0.0 test: `NODE_ENV=test nodemon --exec 'mocha --recursive -R min'`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the muber#1.0.0 test script 'NODE_ENV=test nodemon --exec 'mocha --recursive -R min''.
npm ERR! Make sure you have the latest version of node.js and npm installed.
I think I know what the problem is if it works on Linux but not the Windows machine. Windows cannot run CLI scripts the same; it requires a different syntax.
To fix it, you simply have to do npm install --save cross-env and then in your package.json file, add cross-env to the beginning of the script declaration:
ie:
"scripts": {
"start": "NODE_ENV=test nodemon --exec 'mocha --recursive -R min'"
},
will become:
"scripts": {
"start": "cross-env NODE_ENV=test nodemon --exec 'mocha --recursive -R min'"
},
That should fix it.
To fix it on Windows, you'd have to change it to (I think):
"scripts": {
"start": "NODE_ENV=test&&nodemon --exec 'mocha --recursive -R min'"
},
You can do a quick test and change it to that and run it. If that fixes it, this is exactly your problem. But, that will break it on Linux, so generally, cross-env is recommended. Make sure you dont have spaces also at &&.