【发布时间】:2022-01-22 14:12:38
【问题描述】:
我对此很陌生,也很迷茫。我相信我改变了很多让我目前面临这个问题的事情。最终,我只是想npm run build我的 React.js 项目,以便我可以部署它。但我运行npm run build 并看到此错误:
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
我从中了解到的是,我需要创建一个 package.json 文件,所以我通过运行 npm init 在我的“my-blog”目录中完成了该文件。酷,我这样做了,现在我在“我的博客”中有一个新的 package.json 文件,我手动输入了 "build": "react-scripts build",这样我就可以运行 npm run build 而不会收到错误说我缺少构建脚本。这就是 package.json 文件现在的样子:
{
"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"
}
我再次npm run build,现在得到这个:
my-blog git:(main) ✗ npm run build
> my-blog@1.0.0 build
> react-scripts build
sh: react-scripts: command not found
最后,我认为我遇到了这个问题,因为我的文件可能是如何设置的,所以 here 是事情的样子。
【问题讨论】:
标签: javascript node.js reactjs npm deployment