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" }
Related
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 am trying to install a project and I get a npm 128 error code on one dependency of the project.
npm install
npm ERR! Error while executing:
npm ERR! C:\Program Files\Git\mingw64\bin\git.EXE ls-remote -h -t git#gitlab.mysite.com:myprivaterepo
npm ERR!
npm ERR! Permission denied, please try again.
npm ERR! Permission denied, please try again.
npm ERR! git#gitlab.mysite.com: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).
npm ERR! fatal: Could not read from remote repository.
npm ERR!
npm ERR! Please make sure you have the correct access rights
npm ERR! and the repository exists.
npm ERR!
npm ERR! exited with error code: 128
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\user\AppData\Roaming\npm-cache\_logs\2020-07-13T12_19_31_285Z-debug.log
I am normally using gitBash with agent running in background for ssh connections and I can directly clone from the gitLab repo of the incriminated dependency but i can't from the main project with npm install.
I also tried to execute the command that is throwing the error and it works:
git ls-remote --tags --heads git#gitlab.mysite.com:myprivaterepo
0099c1913ecc392394413554c5b22f2ea0b22b43 refs/heads/feature/generate-manifests
b67ca49f1d6ec9cf77ddd233a4f7b25d7a977d75 refs/heads/master
8787a2dafbfebef21a9cf77c8081b745979e76fe refs/heads/refactor/use-docker-compose-pull
70ee2ca3e44b6dedb4d4cf3984cec20dcf3283be refs/tags/1.0.0
9260ee68b9fd4972f18a51dc7c21d2a8559bc51e refs/tags/1.0.0^{}
fa44564e49035b5c1eecaeb9092332e60b5dfa0a refs/tags/1.0.1
0c3ef1ec8621614c83668841a69769c496d74ee4 refs/tags/1.0.1^{}
86a351644be3994f0bcd8b4cdbd2b9721d296440 refs/tags/1.0.2
f5c24db1d09cc3d35aa35816b8ad5528c60b6d79 refs/tags/1.0.2^{}
cc0b8bf529390eb9c1137aeeee82925b3f37c985 refs/tags/1.0.3
3002e6cce768eff4bdb6872b7856763065e0f545 refs/tags/1.0.3^{}
37fbaa00a3ffe116113af98243bb5abffd4e7d3a refs/tags/1.0.4
fac2008469dd9c1bb20b5a3d811586ee04527664 refs/tags/1.0.4^{}
d209098860a9f6f6b562431a065500bff2b2702f refs/tags/1.0.5
b67ca49f1d6ec9cf77ddd233a4f7b25d7a977d75 refs/tags/1.0.5^{}
Tried also with yarn and I have the same problem.
Tried also different node versions from the latest to the 8.0.0 or deleting and re-installing from scratch node and npm.
This is my package.json:
{
"name": "my-project",
"version": "1.0.0",
"description": "",
"main": "app/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "ssh://git#gitlab.mysite.com/myproject/myfolder"
},
"keywords": [
"my-keyword"
],
"author": "my#email.com",
"license": "mylicense",
"dependencies": {
"my-dependency": "git+ssh://git#gitlab.mysite.ch:my-repo/my-folder/my-repo",
"lodash": "^3.10.1",
"xml2js": "0.4.17"
}
}
Someone has any hint on what's the problem?
Hi Francesco and welcome to SO!
I think the problem is that the git process executed by npm runs out of the scope of your Git Bash, which is a MinGW. It looks like npm executes git.exe in pure windows context, hence it doesn't know anything about your MinGW environment. I would suggest you to place your ssh-keys both in ~/.ssh in Git Bash and in %USERPROFILE%\.ssh in windows. Or to create symbolic links on MinGW side.
I have created an account with npmjs.com also I'm following the how-to-npm tutorial from command line (linux). I'm at the stage where I should publish my test module. But I keep getting error:
You must sign up for private packages : #zentech/node
these are all the error when npm publish
npm ERR! publish Failed PUT 402
npm ERR! Linux 4.10.0-33-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "publish"
npm ERR! node v4.7.2
npm ERR! npm v3.5.2
npm ERR! code E402
npm ERR! You must sign up for private packages : #zentech/node
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR! <https://github.com/npm/npm/issues>
npm ERR! Please include the following file with any support request:
npm ERR! /home/george/node/npm-debug.log
my package.json file
{
"name": "#zentech/node",
"version": "1.0.1",
"main": "index.js",
"preferGlobal": true,
"scripts": {
"test": "node test.js"
},
"author": "",
"license": "ISC",
"description": "",
"repository": "http://github.com/zentech/node"
}
does anyone know why the error? thanks
As suggested in the comments above the way to publish a scoped package i.e.
#scope/my-package
is to use the --access flag when publishing
npm publish --access=public
You do not need to sign up for private packages unless you actually want your package to be private.
Or you can set the public access on package.json:
{
...
"publishConfig": {"access": "public"}
...
}
rather than:
{
...
"publishConfig": {"access": "restricted"}
...
}
You must sign up for private packages: #zentech/node
So you either sign up, or you change the name of your package from #zentech/node to a public name, like zentech-node.
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.
I followed the directions here to install babel-cli. I added "build": "babel src -d lib" to my package.json in the directory I want to run it in. However, on running, I get this error:
🐕 npm run build
> ipfs-readme-standard#1.0.0 build /Users/richard/src/ipfs-readme-standard
> babel src -d lib
src doesn't exist
npm ERR! Darwin 14.5.0
npm ERR! argv "/Users/richard/.nvm/versions/node/v5.0.0/bin/node" "/Users/richard/.nvm/versions/node/v5.0.0/bin/npm" "run" "build"
npm ERR! node v5.0.0
npm ERR! npm v3.5.2
npm ERR! code ELIFECYCLE
npm ERR! ipfs-readme-standard#1.0.0 build: `babel src -d lib`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the ipfs-readme-standard#1.0.0 build script 'babel src -d lib'.
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 ipfs-readme-standard package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! babel src -d lib
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs ipfs-readme-standard
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls ipfs-readme-standard
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /Users/richard/src/ipfs-readme-standard/npm-debug.log
I'm at a loss. Shouldn't src be generated? There's no extra step on babeljs.io that I am missing.
Shouldn't src be generated?
This is the folder that contains the script that you want to be transpiled. If it doesn't exist then babel will throw the error you posted.
Also, take note of what it says at the bottom of page you linked to:
Pre-6.x, Babel enabled certain transformations by default. However, Babel 6.x does not ship with any transformations enabled. You need to explicitly tell it what transformations to run. The simplest way to do this is by using a preset, such as the ES2015 Preset.
This means that even if you create a src directory and place a file containing ES6 code in it, Babel will happily run, but the output will be (almost) identical to the input.
This is a quick example of how to get up and running with the babel-cli.
Create a project, then install the babel-cli package and ES2015 preset:
mkdir babeltest && cd babeltest
touch package.json
npm install babel-cli babel-preset-es2015 --save-dev
Next edit package.json:
{
"name": "my-project",
"version": "1.0.0",
"scripts": {
"build": "babel src -d lib"
},
"scripts": {
"build": "babel --presets es2015 src -d lib"
},
"devDependencies": {
"babel-cli": "^6.0.0"
}
}
Notice that the command in the npm scripts is slightly different to that on the babel homepage, in so far as we're telling it to use the installed presets.
Next make a file in the src directory:
mkdir src && cd src
touch main.js
In main.js add:
[1,2,3].map(x => x * x)
Then run babel via npm:
npm run build
And inspect the output in lib/main.js
"use strict";
[1, 2, 3].map(function (x) {
return x * x;
});
You also get this error when your node modules are not installed, If you download the code from the internet and immediately try running the code, it throws the above error, just run
npm install
and then
npm run build // or other commands should work
In case someone is still looking for solution, check if .babelrc is missing
If so simply create a new .babelrc file and paste the above snippet in it.
{
"presets": ["es2015", "stage-0"]
}