npm start showing weird error 1 - node.js

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.

Related

Why can't I successfully run "npm start" command on mac?

I'm trying to install npm and I keep getting errors. Initially the problem was I needed a package-lock.json file and package.json file and that was solved by typing "npm init" into the terminal.
Then when trying to run "npm start" it said I was missing the start script. So I opened the package.json file to add it as shown below:
{
"name": "arvinder",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node index.js"
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
Now I'm getting the following errors:
Arvinders-MacBook-Air:~ Arvinder$ npm start
npm ERR! file /Users/Arvinder/package.json
npm ERR! code EJSONPARSE
npm ERR! JSON.parse Failed to parse json
npm ERR! JSON.parse Unexpected string in JSON at position 137 while parsing '{
npm ERR! JSON.parse "name": "arvinder",
npm ERR! JSON.parse "version": "1.'
npm ERR! JSON.parse Failed to parse package.json data.
npm ERR! JSON.parse package.json must be actual JSON, not just JavaScript.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/Arvinder/.npm/_logs/2020-07-24T16_26_18_155Z-debug.log
I'm not sure where the error is in the json file or why it can't parse it so if anyone could help point out a solution that would be greatly appreciated.
Seems like you're missing a comma in line 7, after "start": "node index.js". Here's the correct one:
{
"name": "arvinder",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
I recommend you to install an extension for your IDE that can catch syntax errors on JSON files.
I suggest you use vscode.
It will throw an error when you missing a comma.
For example:
the example of missing a comma

Error around package files for Node.js Discord bot

I have a basic Discord bot I am trying to publish through Heroku because I can't host it locally anymore.
Should mention that it runs perfectly fine when hosted locally on my VM.
When trying to push to Heroku through cli or git I am getting an error which says:
npm ERR! cipm can only install packages when your package.json and package-lock.json or npm-shrinkwrap.json are in sync. Please update your lock file with npm install before continuing.
remote: npm ERR!
remote: npm ERR!
remote: npm ERR! Missing: enmap#^5.2.4
remote: npm ERR! Missing: eslint#^7.2.0
Tried googling and and still have no idea how these package files work, so would be grateful if someone could tell me what to change.
package.json
{
"name": "sidbot2",
"version": "2.3.2",
"description": "",
"main": "sidbot.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "sidilleth",
"license": "ISC",
"dependencies": {
"discord.js": "^12.2.0",
"enmap": "^5.2.4"
"eslint": "^7.2.0"
},
"devDependencies": {
"eslint": "^7.2.0"
}
}
Remove the eslint from dependencies as it is already present in the dev dependencies. It should look similar to this:
{
"name": "sidbot2",
"version": "2.3.2",
"description": "",
"main": "sidbot.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "sidilleth",
"license": "ISC",
"dependencies": {
"discord.js": "^12.2.0",
"enmap": "^5.2.4"
},
"devDependencies": {
"eslint": "^7.2.0"
}
}
Delete node_modules folder and execute npm install.
Also make sure that the all the changes made in package.json and package-lock.json has been committed to git.

Trying to install graphql package with node [duplicate]

This question already has answers here:
npm ERR Refusing to install package with name <packageName> under a package also called <packageName>
(2 answers)
Closed 1 year ago.
npm ERR! code ENOSELF
npm ERR! Refusing to install package with name "graphql" under a package
npm ERR! also called "graphql". Did you name your project the same
npm ERR! as the dependency you're installing?
npm ERR!
npm ERR! For more information, see:
Change the name prop on your package.json to anything but graphql
Edit package.json
{
"name": "graphql-basic", # --> change name but don't graphql
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.17.1",
"express-graphql": "^0.12.0",
"graphql": "^15.4.0"
}
}

npm ERR! while installing next.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. :)

Unable to build nodejs app

So I'm trying out this go-react example but I am not able to build it by following the instructions. Running the following command:
~/react-go/jsapp$ npm run build
I get the following error:
> example-js-app#0.0.0 build /home/x/react-go/jsapp
> browserify -t reactify -r react -r ./src/App > ../webapp/static/bundle.js
/usr/bin/env: node: No such file or directory
npm ERR! weird error 127
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
Here's the package.json content:
{
"name": "example-js-app",
"version": "0.0.0",
"description": "",
"main": "index.js",
"scripts": {
"build": "browserify -t reactify -r react -r ./src/App > ../webapp/static/bundle.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {
"envify": "^3.4.0",
"react": "^0.14.0",
"browserify": "^11.2.0",
"reactify": "^1.1.1"
}
}
I'm new to nodejs. What am I doing wrong?

Resources