When I run npm run build I get this error? - javascript

I am pretty new to this and pretty lost as well. I believe I switched up a lot of things which has me facing this problem at the moment. Ultimately, I am just trying to npm run build my React.js project so I could deploy it. But I run npm run build and I see this error:
my-blog git:(main) ✗ npm run build
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path /Users/rondon/code/my-blog/package.json
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, open '/Users/rondon/code/my-blog/package.json'
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! /Users/rondon/.npm/_logs/2022-01-22T05_37_12_010Z-debug.log
What I understood from this is that I need to make a package.json file so I did that in my "my-blog" directory by running npm init. Cool, I do that and now I have a new package.json file in "my-blog" and I manually put in a "build": "react-scripts build" so I can run npm run build without getting an error saying I am missing a build script. This is how that package.json file looks now:
{
"name": "my-blog",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "react-scripts build"
},
"repository": {
"type": "git",
"url": "git+https://github.com/rmera1026/my-blog.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/rmera1026/my-blog/issues"
},
"homepage": "https://github.com/rmera1026/my-blog#readme"
}
I npm run build again and now get this:
my-blog git:(main) ✗ npm run build
> my-blog#1.0.0 build
> react-scripts build
sh: react-scripts: command not found
Lastly, I think I am having this problem because of how my file might be set up as well so here are how things are looking.

Your my-blog project has 2 directories. One is api, another one is client.
You have to build in your client directory, but you're outside of it. Change your directory to client and run npm run build
cd client && npm run build

Related

how to run program when the start script is missing

When I am trying to run my code using npm start I am getting this error -
npm start -
npm ERR! Missing script: "start"
npm ERR!
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!
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\Local\npm-cache_logs\2023-01-20T08_18_49_238Z-debug-0.log
Hi you need to define the start script in the package.json file. For example here in this node project
package.json (remove the comment to use the json):
{
"name": "node-starter",
"version": "0.0.0",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node index.js" // <-- start script here to start a node program
}
}
Full example
https://stackblitz.com/edit/node-g7ntls?file=index.js,package.json
You can use like node entry.js

Npm not running in terminal vite

What I typed: Npm run dev
Error:
npm ERR! Missing script: "dev"
npm ERR!
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\andre\AppData\Local\npm-cache\_logs\2021-11-12T04_58_51_898Z-debug.log
Json:
{
"name": "port",
"version": "0.0.0",
"scripts": {
"dev": "vite",
"build": "vite build",
"serve": "vite preview"
},
"devDependencies": {
"vite": "^2.6.4"
},
"dependencies": {
"three": "^0.134.0"
}
}
If you could help thank you and if not thank you for reading this and taking your time out of your day
Goto you project directory by cd your-project-name.
run npm run dev command and try again (In your npm command "N" is capital).
and if not work please check below link (please refer green tick answer) :
How to resolve npm run dev missing script issues?

poblem with use the npm start in nodejs . 'nodemon' is not recognized as an internal or external command, operable program or batch file

i create a project in ubuntu and i run and deploy that , its worked fine .
now i change the operation system and a use the windows 10 and when i run this code npm start in vscode it show me this error :
> Store#1.0.0 start F:\Projects\Nodejs\Store
> nodemon server.js
'nodemon' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! Store#1.0.0 start: `nodemon server.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the Store#1.0.0 start 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! C:\Users\programmer\AppData\Roaming\npm-cache\_logs\2020-06-27T11_34_26_614Z-debug.log
i install the nodemon :
{
"name": "Store",
"version": "1.0.0",
"description": "",
"main": "server.js",
"scripts": {
"start": "nodemon server.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"nodemon": "^2.0.4"
}
}
and download and install the nodejs in windows .
whats the problem ? how can i solve this problem ??
i solve the problem . i delete all node_module and install that again with npm install command .

npm not running scripts in package.json

The problem is that when I do npm start OR npm run customScriptCommand npm just not doing anything with the project and quickly just return new line in the terminal.
I've tried removing node and npm from my machine and then do brew installation for node and npm, but it does not fix the problem.
Then I tried removing node and npm from the brew installation and installing it again from nvm, but it also does not fix the problem.
NPM Details
npm -v -> 6.11.3
which npm -> /usr/local/bin/npm
NodeJS Details
node -v -> v12.12.0
which node ->/usr/local/bin/node
Scripts in package.json
"scripts": {
"start": "node ./bin/www",
"devstart": "DEBUG=app-name:* nodemon ./bin/www", //I've changed my actual app name to "app-name"
},
If I do node ./bin/www OR DEBUG=app-name:* nodemon ./bin/www it will work:
Update
I've tried on other project that does not have problem on my colleague's machine, with git clone do npm install and tried to run the project, but it still failed
Even with fresh project which I just did npm init -y it fail,
{
"name": "test"
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "itsme",
"license": "ISC"
}
npm config set ignore-scripts false would do the trick for you.
The struggle is real my friend, not following random tutorials from now.
https://github.com/npm/cli/issues/541
Installing npm install --save-dev nodemon and running npm start did the magic for me
You can install yarn and it works; just run yarn start. As to what caused the problem I have no idea.

Using external JS library in React server

I have to use a JS library called 'react-armor' here for my web project. So, created a React powered server as instructed here.
The server is up and running. But, in order to use the react-armor library, the code specifies to import the library into the project JS:
import { obfuscateClassNames } from 'react-armor';
*as in the readme.md tutorial of react-armor github
But, how could I use the package react-armor (examples given in the readme.md) into my react server? I mean, how to integrate the github repo to my server? Just using import something from 'react-armor', so where should react-armor exist?
Update 1:
Added react-armor dependency in server package.json file.
But, sudo npm install --save react-armor gives me errors.
npm http GET https://registry.npmjs.org/react-armor
npm http 404 https://registry.npmjs.org/react-armor
npm ERR! TypeError: Cannot read property 'latest' of undefined
npm ERR! at next (/usr/share/npm/lib/cache.js:687:35)
npm ERR! at /usr/share/npm/lib/cache.js:675:5
npm ERR! at saved (/usr/share/npm/node_modules/npm-registry-client/lib/get.js:142:7)
npm ERR! at /usr/lib/nodejs/graceful-fs/polyfills.js:133:7
npm ERR! at Object.oncomplete (fs.js:107:15)
npm ERR! If you need help, you may report this log at:
npm ERR! <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR! <npm-#googlegroups.com>
npm ERR! System Linux 3.13.0-87-generic
npm ERR! command "/usr/bin/nodejs" "/usr/bin/npm" "install" "react-armor"
npm ERR! cwd /home/local/unixroot
npm ERR! node -v v0.10.25
npm ERR! npm -v 1.3.10
npm ERR! type non_object_property_load
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /home/local/unixroot/npm-debug.log
npm ERR! not ok code 0
Even after adding the dependency in package.json file, the import doesn't work.
This is my package.json in my react server folder:
{
"name": "react-tutorial",
"version": "0.0.0",
"private": true,
"license": "see LICENSE file",
"description": "Code from the React tutorial.",
"main": "server.js",
"dependencies": {
"react-armor": "elierotenberg/react-armor",
"body-parser": "^1.4.3",
"express": "^4.4.5"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server.js"
},
"repository": {
"type": "git",
"url": "https://github.com/reactjs/react-tutorial.git"
},
"keywords": [
"react",
"tutorial",
"comment",
"example"
],
"author": "petehunt",
"bugs": {
"url": "https://github.com/reactjs/react-tutorial/issues"
},
"homepage": "https://github.com/reactjs/react-tutorial",
"engines" : {
"node" : "0.12.x"
}
}
Update 1:
It seems like some dependency errors here. But, is it possible to run this on Tomcat instead of NodeJS? Why does everyone recommend using NodeJS for ReactApp instead of Tomcat, despite React being a client side rendered JS lib?
If it's an NPM package, you would run npm install --save react-armor (--save if you want to add it to your down package's dependencies). It will download it and save it into a ./node_modules folder. Node will automatically look in that path (in addition to other preset locations) to find that module.
If it's not hosted on NPM, you can pull it in from GitHub by adding this to your package.json file.
"dependencies": {
"react-armor": "elierotenberg/react-armor"
}
Where the url is user/repo. You would still need to run npm install to actually download it.

Categories

Resources