简体   繁体   中英

When I run npm run build I get this error?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM