npm ERR! while installing next.js - node.js

I have a problem like while I am trying to install next.js using npm install --save next then showing below error like
npm ERR! Unexpected end of JSON input while parsing near '...:{"eslint":"3.19.0","'
I just stack into that for past several hours.
How can I resolve that?
package.json
{
"name": "a-client-project",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"dev": "node server.js -p $PORT",
"build": "next build",
"start": "NODE_ENV=production node server.js -p $PORT"
},
"author": "",
"license": "ISC",
"dependencies": {
"body-parser": "^1.19.0",
"express": "^4.17.1",
"react": "^16.9.0",
"react-dom": "^16.9.0"
}
}
Info:
OS: Windows 10
NodeJS: 10.16.3
NPM: 6.11.3
Thanks

The issue was due to the node cache.
npm cache clean --force
fixed the issue.
Writing answer here in case anyone else runs across this. :)

Related

Heroku deployment throws an error every time: Missing script: "build"

everyone. I've been trying to deploy a simple MERN application on Heroku for some time now, unfortunately without success so far! I usually get the error message from Heroku (See below).
I did everything exactly according to the plan as described here https://github.com/safak/youtube/tree/free-deployment for a FullStack App. I also have other applications that have also been successfully deployed on Heroku, with the same structure. However, there was no problem. Have I overlooked something?
remote: npm ERR! Missing script: "build"
remote: npm ERR!
remote: npm ERR! To see a list of scripts, run:
remote: npm ERR! npm run.
{
"name": "server",
"version": "1.0.0",
"description": "",
"main": "index.js",
"type": "module",
"scripts": {
"start": "node index.js",
"heroku-postbuild": "cd client && npm install && npm run build"
},
"engines": {
"node": "18.6.0"
},
"cacheDirectories": [
"node_modules",
"client/node_modules"
],
"author": "",
"license": "ISC",
"dependencies": {
"cookie-parser": "^1.4.6",
"cors": "^2.8.5",
"dotenv": "^16.0.1",
"express": "^4.18.1",
"mongoose": "^6.5.2",
"nodemon": "^2.0.19",
"path": "^0.12.7",
"react-scripts": "^5.0.1"
},
"devDependencies": {
"react-scripts": "^5.0.1"
}
}

Install custom npm package in another custom npm package

I have create a npm package to install "gulp" & "nunjucks" and some other features of gulp. and published it in NPM repository named (package name: xdnunjucks-test).
Now I have created new project and trying to install "xdnunjucks-test" then it is added to my new project but all the dependencies in xdnunjucks-test are not added to new project.
command: npm install xdnunjucks-test
-- I should create a custom NPM package to install all dependencies in my new projects. This will helps me to avoid run all the commands in xdnunjucks-test everytime.
single command to run multiple commands.
here are my package.json file content.
Published Custom NPM command - package.json:
{
"name": "xdnunjucks-test",
"version": "1.0.5",
"description": "Custom npm command creation",
"main": "index.js",
"scripts": {
"test": "XDNunjucks",
"start": "npm install gulp",
"bootstrap-gulp": "npm i bootstrap-gulp",
"gulp-uglify": "npm install gulp-uglify",
"gulp-sass": "npm install node-sass gulp-sass",
"gulp-imagemin": "npm install gulp-imagemin",
"gulp-minify": "npm install gulp-minify",
"gulp-livereload": "npm install gulp-livereload",
"gulp-data": "npm install gulp-data",
"browser-sync": "npm install browser-sync"
},
"keywords": [
"npm",
"test"
],
"author": "Anil",
"license": "ISC",
"devDependencies": {
"browser-sync": "^2.26.7",
"gulp": "^4.0.2",
"gulp-data": "^1.3.1",
"gulp-imagemin": "^7.1.0",
"gulp-livereload": "^4.0.2",
"gulp-minify": "^3.1.0",
"gulp-nunjucks-render": "^2.2.3",
"gulp-sass": "^4.0.2",
"gulp-uglify": "^3.0.2",
"node-sass": "^4.13.1"
},
"dependencies": {
"bootstrap-gulp": "^2.2.5"
}
}
new project package.json:
{
"name": "n-test-2",
"version": "1.0.0",
"description": "",
"main": "gulpfile.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"xdnunjucks-test": "^1.0.5"
}
}
After installing the "xdnunjucks-test" command. I didn't get the features of "xdnunjucks-test" in new project.
Please help in in this.
Thank you.
All the dependencies in you package xdnunjucks-test is only "bootstrap-gulp" "^2.2.5"
all other dependency from devDependency will not be installer in package.
For example if you need to use gulp-uglify in installed package xdnunjucks-test - you should move it to dependency
devDependencies are:
installed on npm install on a directory that contains package.json, unless you pass the --production flag (go upvote Gayan Charith's answer).
not installed on npm install "$package" on any other directory, unless you give it the --dev option.
are not installed transitively.
You can find more about npm dependency on stackoverflow and npm documentation

Why is npm start error creating react app

I'm learning reactjs
I started with installing nodejs
and then ran these commands inside my project folder "React"
npx create-react-app hello-world
cd hello-world
npm start
but then instead of going to the browser i receive error:
npm ERR! missing script: start
npm ERR! A complete log of this run can be found in: npm ERR!
C:\Users\abc\AppData\Roaming\npm-cache_logs\2020-02-21T13_34_26_640Z-debug.log
PACKAGE.JSON CODE:
{
"name": "hello-world",
"version": "0.1.0",
"private": true,
"dependencies": {
"react": "^16.12.0",
"react-dom": "^16.12.0",
"react-scripts": "3.4.0"
}
}
Help me solve this error i dont want it to demotivate me from learning React
npm scripts are missing inside your package.json file
npm ERR! missing script: start
Edit your package.json as follows:
{
"name": "hello-world",
"version": "0.1.0",
"private": true,
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build"
},
"dependencies": {
"react": "^16.12.0",
"react-dom": "^16.12.0",
"react-scripts": "3.4.0"
}
}
I was also facing almost same type of problem. But then tried
yarn create react-app my-app
in power shell with admin privilege which seemed to do the trick.
Also you’ll need to have Node >= 8.10, yarn >= 0.25+ on your machine
as the official doc suggests.

error while pushing node js project to heroku

I am getting this error while I am trying to push my project to heroku. Backend is writtend in nodeJS, frontend in React. I think the problem is heroku-postbuild, because if I remove it, push works. I was searching for it but still I have no idea what is the reason. Can somebody help me?
/tmp/build_7504975f08f330415cdefb27437cfad9/node_modules/.bin/node: 1: /tmp/build_7504975f08f330415cdefb27437cfad9/node_modules/.bin/node: MZ����#: not found
/tmp/build_7504975f08f330415cdefb27437cfad9/node_modules/.bin/node: 1: /tmp/build_7504975f08f330415cdefb27437cfad9/node_modules/.bin/node: Syntax error: word unexpected (expecting ")")
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! project#1.0.0 heroku-postbuild: `cd client && npm install && npm run build`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the project#1.0.0 heroku-postbuild 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! /tmp/npmcache.W89m8/_logs/2018-11-13T21_37_22_676Z-debug.log
-----> Build failed
We're sorry this build is failing! You can troubleshoot common issues here:
https://devcenter.heroku.com/articles/troubleshooting-node-deploys
Some possible problems:
- node_modules checked into source control
https://blog.heroku.com/node-habits-2016#9-only-git-the-important-bits
- Node version not specified in package.json
https://devcenter.heroku.com/articles/nodejs-support#specifying-a-node-js-version
Love,
Heroku
! Push rejected, failed to compile Node.js app.
! Push failed
package.json (server)
{
"name": "project",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node server.js",
"server": "nodemon server.js",
"client-install": "npm install --prefix client",
"client": "npm start --prefix client",
"dev": "concurrently \"npm run server\" \"npm run client\"",
"heroku-postbuild": "cd client && npm install && npm run build"
},
"author": "",
"license": "ISC",
"dependencies": {
"concurrently": "^4.0.1",
"express": "^4.16.4",
"jsonwebtoken": "^8.3.0",
"mongoose": "^5.3.4",
"node": "^8.10.0",
"nodemon": "^1.18.4",
"passport": "^0.4.0",
"passport-jwt": "^4.0.0",
"react-scripts": "1.0.11",
},
"devDependencies": {
"nodemon": "^1.18.4",
"react-scripts": "1.0.11"
}
}
package.json (client)
{
"name": "client",
"version": "0.1.0",
"private": true,
"dependencies": {
"parallelshell": "^3.0.2",
"react-dom": "^16.5.2",
"react-redux": "^5.0.7",
"react-router": "^4.3.1",
"react-router-dom": "^4.3.1",
"react-router-redux": "^4.0.8",
"react-scripts": "2.0.5",
"socket.io-client": "^1.7.3",
},
"scripts": {
"start": "parallelshell \"react-scripts start\" \"sass --watch src/styles/scss:src/styles/css --style compressed\"",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"sass": "sass --watch src/styles/scss:src/styles/css --style compressed",
"sass-nw": "sass src/styles/scss:src/styles/css"
},
"proxy": "http://localhost:5000/",
}
I ran into the similar error while troubleshooting a project. I resolved it by using the suggestions from the prompt.
Some possible problems:
- node_modules checked into source control
https://blog.heroku.com/node-habits-2016#9-only-git-the-important-bits
- Node version not specified in package.json
https://devcenter.heroku.com/articles/nodejs-support#specifying-a-node-js-version
So try do a "rm -rf node_modules" in the root directory if you checked node_modules into the repository. Heroku will install node_modules in the deployed environment and does not need your checked in version.

npm start showing weird error 1

I am new to react js and I have installed the dependencies for the application. Below is my package file:
package.json
{
"name": "reactapp",
"version": "0.0.0",
"description": "learn and test",
"main": "index.js",
"scripts": {
"start": "webpack-dev-server --hot"
},
"author": "john doe",
"license": "BSD-2-Clause",
"dependencies": {
"webpack": "~1.13.3",
"webpack-dev-server": "~1.16.2",
"react": "~15.3.2",
"react-dom": "~15.3.2"
},
"devDependencies": {}
}
It throws the error:
npm ERR! weird error 1
npm WARN This failure might be due to the use of legacy binary "node"
npm WARN For further explanations, please read
/usr/share/doc/nodejs/README.Debian
npm ERR! not ok code 0
But, in the terminal while it doesn't show up anything when in scripts it is
"test": "echo \"Error: no test specified\" && exit 1"
You need to use the sudo command while installing nodejs-legacy.
Executing sudo apt-get install nodejs-legacy from your command line/shell will resolve the issue.

Resources