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?
Related
I get this error when I run npm start.
npm ERR! Missing script: "start"
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! To see a list of scripts, run:
npm ERR! npm run
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\USER\AppData\Local\npm-cache\_logs\2022-04-28T13_04_19_260Z-debug.log
package.json has various sections, scripts is one of them, which allows you to write npm scripts which we can run using npm run <script-name>. The error you're getting is because your start script is missing in that section.
For a node app, your package.json file should look similar to this.
{
"name": "server",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"start": "node app.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"body-parser": "^1.20.0",
"cors": "^2.8.5",
"express": "^4.17.3"
}
}
In the above code, focus on the scripts section. The following line is missing in your package.json file.
"scripts": {
"start": "node app.js",
},
Add this line and you're good to go.
Option_1: Control inside file "package.json":
"scripts": {
"start": "what command is here?",
},
Option_2: Control Terminal (folder) where you write command OR open the responding terminal for your project: right-click
on the project name -> "Open in integrated Terminal"
You have to put what command you need npm to run when you give npm start.
You have to write node index.js in scripts.start in your package.json file
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
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.
Given the following excerpt from package.json:
{
"name": "foo",
"version": "0.0.1",
"description": "Foo",
"main": "bin/index.js",
"bin": "bin/index-cli.js",
"private": true,
"scripts": {
"install": "tsc",
"test": "echo \"Error: no test specified\" && exit 1"
},
...
}
npm install fails with:
npm ERR! enoent ENOENT: no such file or directory, chmod '/home/mk/work/my-project/node_modules/foo/bin/index-cli.js'
Which is, because the install script (tsc - typescript compiler), which generates bin/index-cli.js from src/index-cli.ts is not executed before npm tries to create the sym link.
Question: What is the right way to have a bin, which is generated by an install script?
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.