I'm trying to start a new project using gruntjs.
I have this project structure:
grunt-test (dir)
|_ index.html
|_ package.json
|_ Gruntfile.js
|_ assets (dir)
|_ _js (dir)
|_ scripts.js
|_ _sass (dir)
|_ style.sass
I have nodejs and grunt installed.
So, when I go to project's folder and use this command line on terminal: npm install grunt --save-dev
It returns me all those errors:
npm ERR! Failed to parse json
npm ERR! Unexpected end of input
npm ERR! File: /Applications/XAMPP/xamppfiles/htdocs/grunt-test/package.json
npm ERR! Failed to parse package.json data.
npm ERR! package.json must be actual JSON, not just JavaScript.
npm ERR!
npm ERR! This is not a bug in npm.
npm ERR! Tell the package author to fix their package.json file. JSON.parse
npm ERR! System Darwin 11.4.2
npm ERR! command "node" "/usr/local/bin/npm" "install" "grunt" "--save-dev"
npm ERR! cwd /Applications/XAMPP/xamppfiles/htdocs/grunt-test
npm ERR! node -v v0.10.26
npm ERR! npm -v 1.4.3
npm ERR! file /Applications/XAMPP/xamppfiles/htdocs/grunt-test/package.json
npm ERR! code EJSONPARSE
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /Applications/XAMPP/xamppfiles/htdocs/grunt-test/npm-debug.log
npm ERR! not ok code 0
I've been trying to install it for a while and I haven't had any success. I don't know what I'm doing wrong. I'm following all the instructions on gruntjs docs. Can someone help me?
Your package.json is not a valid JSON. Instead of typing in commands, you can add these as devDependencies in your package.json file and then use npm install which will install packages from the package.json file. You can use the below.
{
"name": "Project Name",
"version": "1.0.0",
"devDependencies": {
"grunt": "0.4.4",
"grunt-cli": "0.1.13"
}
}
Run npm install grunt-cli -g if grunt is not found message gets displayed.
In your package.json, strings are enclosed into single quotes ('), it makes it a non-valid JSON data. JSON expects strings to be enclosed into double quotes (").
Related
I have written a command line utility in JS which can be used to backup data to IPFS.
https://www.npmjs.com/package/ipfs-backup
When I am attempting to install it with npm install -g ipfs-backup I am getting an error which prevents the package from being installed.
The terminal is outputting the following:
npm ERR! code ENOENT
npm ERR! syscall chmod
npm ERR! path C:\Users\jwhit\AppData\Roaming\npm\node_modules\ipfs-backup\node index.js
npm ERR! errno -4058
npm ERR! enoent ENOENT: no such file or directory, chmod 'C:\Users\jwhit\AppData\Roaming\npm\node_modules\ipfs-backup\node index.js'
npm ERR! enoent This is related to npm not being able to find a file.
The issue turned out to be that within my package.json file I had
"bin": {
"ipfs-backup": "node index.js",
"ipfs-restore": "node restore.js"
}
instead of
"bin": {
"ipfs-backup": "./index.js",
"ipfs-restore": "./restore.js"
}
It installs and functions correctly now.
I'm runnig command :
npm install udev
And I'm getting this error:
npm WARN enoent ENOENT: no such file or directory, open '/home/mitesh/package.json'
npm WARN mitesh No description
npm WARN mitesh No repository field.
npm WARN mitesh No README data
npm WARN mitesh No license field.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! udev#0.6.0 install: `node-pre-gyp install --fallback-to-build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the udev#0.6.0 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/mitesh/.npm/_logs/2020-03-16T11_44_35_032Z-debug.log
Looks like you do not have a package.json in your project or it is probably not rightly placed. Here is what you can do;
Browse to your project directory and run this command;
npm init
This should create a package.json file in your project directory
Then run,
npm install udev --save
--save will ensure your module is saved as a dependency in your package.json file.
you could just try to run the last command without the --save but in some cases it helps
Here is a link to further assist: npm WARN enoent ENOENT: no such file or directory, open 'C:\Users\Nuwanst\package.json'
Try this let me know if it helps.
I am trying to create a local server for visual studio code through Node by following Microsoft's Blog Post. I followed these very simple instructions exactly by adding a package.json file in my root folder and running npm install first. When I do, I get the following error:
$ npm install
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" "install"
npm ERR! node v6.10.2
npm ERR! npm v3.10.10
npm ERR! file C:\Users\Temple\desktop\secret\package.json
npm ERR! code EJSONPARSE
npm ERR! Failed to parse json
npm ERR! Unexpected token '“' at 2:4
npm ERR! “name”: “Demo”,
npm ERR! ^
npm ERR! File: C:\Users\Temple\desktop\secret\package.json
npm ERR! Failed to parse package.json data.
npm ERR! package.json must be actual JSON, not just JavaScript.
npm ERR!
npm ERR! This is not a bug in npm.
npm ERR! Tell the package author to fix their package.json file. JSON.parse
npm ERR! Please include the following file with any support request:
npm ERR! C:\Users\Temple\desktop\secret\npm-debug.log
And yes, I have node installed.
You are using the wrong type of quotes ( windows type ) use this character : "
It looks like you edited the package.json with an editor that automatically uses "smart quotes" (like Microsoft Word, for example). Try retyping the “ characters in Notepad, for example, and see if it works then.
The error message in you package.json
You must use double quotes.
Check and validate your package.json file in here
It looks like when you copy pasted
"name": "Demo”,
it got changed to
“name”: “Demo”,
The problem is with the quotes. Replace all instances of “ or ” with ", and you should be good.
I try to install Spectron, by using this command:
npm install --save-dev spectron
but I get this Err msg:
npm ERR! Windows_NT 6.1.7601 npm ERR! argv "C:\Program
Files\nodejs\node.exe" "C:\Program Files\nodejs\
node_modules\npm\bin\npm-cli.js" "install" "--save-dev" "spectron"
npm ERR! node v6.9.2 npm ERR! npm v3.10.9 npm ERR! code ENOSELF
npm ERR! Refusing to install spectron as a dependency of itself 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! C:\spectron-master\npm-debug.log
What i'm doing wrong?
If you don't set any name in the package.json by default the folder name is taken.
You can't install a Package which is same like the name in package.json.
example : trying to install Spectron in a project having the name Spectron in package.json is supposed to raise this error.
To get started I ran:
npm install --save-dev babel-cli
npm install --save-dev babel-preset-es2015
npm install --save-dev babel-preset-stage-0
Here is my package.json:
{
"scripts": {
"build": "babel src -d dist"
},
"devDependencies": {
"babel-cli": "^6.6.5",
"babel-core": "^6.7.2",
"babel-preset-es2015": "^6.6.0",
"babel-preset-stage-0": "^6.5.0"
}
}
Here is my .babelrc file:
{
"presets": ["es2015", "stage-0"]
}
My file structure is like this:
- Root
- src
- client
- server
- test
- dist
- package.json
I am calling npm run build from the root folder. I am expecting it to compile the source folder into the dist folder. It runs and then I get this error:
> babel src -d dist
sh: babel: command not found
npm ERR! Darwin 15.2.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "build"
npm ERR! node v5.8.0
npm ERR! npm v3.7.3
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! redacted#1.0.0 build: `babel src -d dist`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the redacted#1.0.0 build script 'babel src -d dist'.
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 redacted package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! babel src -d dist
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs redacted
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls redacted
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /Users/user/redacted/npm-debug.log
So as you can see, I've installed babel-cli, I've installed the presets, and I think everything is in order according to the babel docs.
Does anyone have ideas about why it wouldn't be working? Could I be missing a babel npm file? Is "babel src -d dist" incorrect?
Thanks for any help you can provide!
I made another folder and followed the same steps, it worked perfectly. For some reason it's not working in this directory.
I've come across the same issue lately. Removing the node_modules folder and running npm install again no longer fixes the issue.
The reason you are getting this error is because babel-cli needs to be installed globally, not as a project dependency.
Run npm install -g babel-cli to install it globally.
Babel-preset-es2015 can then be installed as a dev dependency for your projects npm install --save-dev babel-preset-es2015
You should never install babel-cli globally - in fact, they specifically have an entire paragraph telling you not to from their official docs.
Edit package.json >> add a script with the key called, say, build with the value ./node_modules/.bin/babel <commands>
If you called it build, just then type npm run build.
The error occurs because ./node_modules/.bin is not in $PATH. ./node_modules/.bin is where all the executable binaries can be found.
As recommended by the documentation, you can reference the babel cli inside of node_modules:
$ ./node_modules/.bin/babel src -d lib
You can modify your npm run build command to use this:
"scripts": {
"build": "./node_modules/.bin/babel src -d dist"
},
Did you run "npm install" to install the dev packages?
Many of the answers above are correct.
The error occurs because ./node_modules/.bin is not in $PATH. ./node_modules/.bin is where all the executable binaries can be found.
What I did was I built a simple dynamic alias function in my zshrc file.
# Babel
function bbl() {
./node_modules/.bin/babel "$#"
}
Now you can use bbl instead of babel
bbl --version
6.24.1 (babel-core 6.25.0)