尝试将react-app部署到Vercel时出现错误(错误:命令“yarn run build”以1退出)

问题描述 投票:0回答:3

我一直在尝试将 create-react-app 部署到 vercel,但不断收到以下错误。一切都在本地运行,甚至构建时没有错误。我该如何修复它?我已经尝试获取 vercel 项目设置上的变量,但什么也没有。

我使用

npm run build
进行构建,并且对 Yarn 不执行任何操作,所以我不明白。

14:50:48    511[1/4] Resolving packages                                                                                 
14:50:49    609[2/4] Fetching packages                                                                                  
14:51:06    414info fsevents@2  3   2: The platform "linux" is incompatible with this module                                                                            
14:51:06    414info "fsevents@2 3   2" is an optional dependency and failed compatibility check  Excluding it from installation                                                                     
14:51:06    431info fsevents@1  2   13: The platform "linux" is incompatible with this module                                                                           
14:51:06    431info "fsevents@1 2   13" is an optional dependency and failed compatibility check     Excluding it from installation                                                                     
14:51:06    444[3/4] Linking dependencies                                                                                   
14:51:06    446warning " > @testing-library/user-event@12   8   3" has unmet peer dependency "@testing-library/dom@>=7  21  4"                                                                  
14:51:06    447warning " > react-lottie@1   2   3" has incorrect peer dependency "react@^0  14  7 || ^15    0   0 || ^16    0   0"                                                  
14:51:06    451warning "react-scripts > @typescript-eslint/eslint-plugin > tsutils@3    20  0" has unmet peer dependency "typescript@>=2    8   0 || >= 3   2   0-dev || >= 3   3   0-dev || >= 3   4   0-dev || >= 3   5   0-dev || >= 3   6   0-dev || >= 3   6   0-beta || >= 3  7   0-dev || >= 3   7   0-beta" 
14:51:20    599[4/4] Building fresh packages                                                                                    
14:51:21    325success Saved lockfile                                                                                   
14:51:21    331Done in 32   90s                                                                             
14:51:21    551Running "yarn run build"                                                                                 
14:51:21    736yarn run v1  22  10                                                                          
14:51:21    764$ CI=false && react-scripts build                                                                                    
14:51:23    059Creating an optimized production build                                                                                   
14:51:23    841Browserslist: caniuse-lite is outdated    Please run:                                                                                
14:51:23    842npx browserslist@latest --update-db                                                                                  
14:51:23    842                                                                                 
14:51:23    842Why you should do it regularly:                                                                                  
14:51:23    842https://github   com/browserslist/browserslist#browsers-data-updating                                                                                
14:51:26    498Failed to compile                                                                                    
14:51:26    498                                                                                 
14:51:26    502 /src/components/header/Banner   js                                                                          
14:51:26    502Cannot find file 'C:/Users/gabri/OneDrive/Documentos/React/portifolio/src/assets/img/profile/eu  png' in '   /src/components/header'                                                                         
14:51:26    502                                                                                 
14:51:26    503                                                                                 
14:51:26    526 error Command failed with exit code                                                                                 
14:51:26    526 info Visit https://yarnpkg  com/en/docs/cli/run for documentation about this command                                                                                
14:51:26    542 Error: Command "yarn run build" exited with 1

我的package.json

{
  "name": "portifolio",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^5.11.4",
    "@testing-library/react": "^11.1.0",
    "@testing-library/user-event": "^12.1.10",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-lottie": "^1.2.3",
    "react-scripts": "4.0.3",
    "web-vitals": "^1.0.1"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "CI=false && react-scripts build",  
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}
npm yarnpkg vercel
3个回答
1
投票

错误消息显示:

找不到文件 'C:/Users/gabri/OneDrive/Documentos/React/portifolio/src/assets/img/profile/eu png' 在'/src/components/header'中

检查您是否在标头组件中正确引用了此文件。


1
投票

而不是在package.json中写CI false 在 Vercel 中,当您从 GitHub 选择项目时,在 Configure Project 框中,您可以添加环境变量,因为 Name

CI
VALUE
false
然后部署它,我认为它会解决您的问题。


0
投票

我遇到了同样的错误,你必须检查你正在使用的节点版本。 Node 版本 18 会给你这个错误,也许你正在使用 Node v16。就我而言,我使用的是版本 16。 mi 的解决方案如下: 在package.json中

"engines": {
"node": "16"

},

© www.soinside.com 2019 - 2024. All rights reserved.