运行 npm run build 时出错
我尝试为 React 项目创建构建文件夹,但是当我运行命令“npm run build”时出现此错误
(base) tazar@Tazs-Air nft-minter-tutorial-main % npm run build
npm ERR! Missing script: "build"
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! /Users/tazar/.npm/_logs/2022-02-25T01_15_14_544Z-debug.log
Im trying to create my built folder for a react project, but I get this error when I run the command 'npm run build'
(base) tazar@Tazs-Air nft-minter-tutorial-main % npm run build
npm ERR! Missing script: "build"
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! /Users/tazar/.npm/_logs/2022-02-25T01_15_14_544Z-debug.log
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在 package.json 文件中添加构建脚本,例如:
in your package.json file add build script, for example:
您可以检查标准的react package.json(位于项目的根文件夹中)文件:
You can check standard react package.json(which is located in root folder of your project) file:
如果在 package.json 文件中定义了构建,请确保您在正确的文件夹层次结构中执行“npm run build”(使用不带参数的“cd”或“pwd”)。
If the build is defined in your package.json file, make sure that you are executing the 'npm run build' in the correct folder hierarchy( use 'cd' with no arguments or 'pwd').
我在运行命令时遇到了同样的问题
我发现我在错误的文件夹中运行命令,因此出现了错误。当我移动到主项目的文件夹并运行相同的命令时,它工作得很好。
我认为你也犯了同样的错误。
例如:
如果您创建了一个文件夹 new_project,然后在该文件夹(new_project)中创建了 React 应用程序,例如 npx create-react-app project_folder
那么您必须始终在此特定文件夹中运行该命令
。
I was facing the same issue while running the command
What I found was that I was running the command in the wrong folder and hence the error was sited. When I moved to the folder of my main project, and ran the same command it worked perfectly.
I think you are making the same mistake.
For eg:
If you have created a folder new_project, and then have created the react app in the folder(new_project) say, npx create-react-app project_folder
Then you must always run the command
in this particular folder.