错误!命令 "npm run build" 以 1 退出,同时使用 vercel 命令部署网站

Error! Command "npm run build" exited with 1, while deploying a website using vercel command

我正在尝试使用以下命令从我的 VSCode 命令行在 Vercel 上部署一个网站:

vercel

当我执行这个命令时,我得到这个输出:

如果我运行:

vercel logs demo-minting-frontend-rga7f9q73-hemang-h.vercel.app

我得到如下输出:

PS C:\CS\Three.js\Marketplace-three\Self-coded-creation> vercel logs demo-minting-frontend-rga7f9q73-hemang-h.vercel.app
Vercel CLI 24.0.0
> Fetched deployment "demo-minting-frontend-rga7f9q73-hemang-h.vercel.app" in hemang-h [1s]
2022-03-07T15:36:56.106Z  
2022-03-07T15:36:56.112Z  Retrieving list of deployment files...
2022-03-07T15:36:57.506Z  Downloading 49 deployment files...
2022-03-07T15:36:58.268Z  Analyzing source code...
2022-03-07T15:36:58.657Z  Installing build runtime...
2022-03-07T15:37:01.398Z  Build runtime installed: 2.741s
2022-03-07T15:37:02.062Z  Looking up build cache...
2022-03-07T15:37:05.865Z  Build cache downloaded [87.05 MB]: 3377.740ms
2022-03-07T15:37:06.003Z  Detected package.json
2022-03-07T15:37:06.004Z  Installing dependencies...
2022-03-07T15:37:06.011Z  Detected `package-lock.json` generated by npm 7...
2022-03-07T15:37:07.781Z  npm WARN deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
2022-03-07T15:37:08.047Z  
2022-03-07T15:37:08.048Z  added 1 package, and changed 1 package in 2s
2022-03-07T15:37:08.048Z
2022-03-07T15:37:08.048Z  116 packages are looking for funding
2022-03-07T15:37:08.048Z    run `npm fund` for details
2022-03-07T15:37:08.257Z  Detected `package-lock.json` generated by npm 7...
2022-03-07T15:37:08.257Z  Running "npm run build"
2022-03-07T15:37:08.537Z
2022-03-07T15:37:08.537Z  > demo-minting-page@1.0.0 build
2022-03-07T15:37:08.537Z  > next build
2022-03-07T15:37:08.537Z
2022-03-07T15:37:09.158Z  warn  - SWC minify release candidate enabled. https://nextjs.org/docs/messages/swc-minify-enabled
2022-03-07T15:37:09.177Z  Attention: Next.js now collects completely anonymous telemetry regarding usage.
2022-03-07T15:37:09.177Z  This information is used to shape Next.js' roadmap and prioritize features.
2022-03-07T15:37:09.177Z  You can learn more, including how to opt-out if you'd not like to participate in this anonymous program, by visiting the following 
URL:
2022-03-07T15:37:09.177Z  https://nextjs.org/telemetry
2022-03-07T15:37:09.177Z
2022-03-07T15:37:09.218Z  info  - Checking validity of types...
2022-03-07T15:37:11.594Z
2022-03-07T15:37:11.594Z  Failed to compile.
2022-03-07T15:37:11.595Z
2022-03-07T15:37:11.595Z  ./pages/404.js
2022-03-07T15:37:11.595Z  18:9  Warning: passHref is missing. See: https://nextjs.org/docs/messages/link-passhref  @next/next/link-passhref
2022-03-07T15:37:11.595Z
2022-03-07T15:37:11.595Z  ./pages/Landing.js
2022-03-07T15:37:11.595Z  6:10  Error: 'Text' is defined but never used. Allowed unused vars must match /^_/u.  no-unused-vars
2022-03-07T15:37:11.595Z  6:16  Error: 'Flex' is defined but never used. Allowed unused vars must match /^_/u.  no-unused-vars
2022-03-07T15:37:11.595Z  7:10  Error: 'useState' is defined but never used. Allowed unused vars must match /^_/u.  no-unused-vars
2022-03-07T15:37:11.596Z  13:5  Error: 'success' is assigned a value but never used. Allowed unused vars must match /^_/u.  no-unused-vars
2022-03-07T15:37:11.596Z  15:5  Error: 'owned' is assigned a value but never used. Allowed unused vars must match /^_/u.  no-unused-vars
2022-03-07T15:37:11.596Z  16:5  Error: 'owner' is assigned a value but never used. Allowed unused vars must match /^_/u.  no-unused-vars
2022-03-07T15:37:11.596Z  26:5  Error: 'reset' is assigned a value but never used. Allowed unused vars must match /^_/u.  no-unused-vars
2022-03-07T15:37:11.596Z
2022-03-07T15:37:11.596Z  ./pages/index.js
2022-03-07T15:37:11.596Z  92:11  Warning: passHref is missing. See: https://nextjs.org/docs/messages/link-passhref  @next/next/link-passhref
2022-03-07T15:37:11.596Z  182:11  Warning: passHref is missing. See: https://nextjs.org/docs/messages/link-passhref  @next/next/link-passhref
2022-03-07T15:37:11.596Z
2022-03-07T15:37:11.596Z  ./pages/mint.js
2022-03-07T15:37:11.597Z  1:30  Error: 'SimpleGrid' is defined but never used. Allowed unused vars must match /^_/u.  no-unused-vars
2022-03-07T15:37:11.597Z  1:42  Error: 'Divider' is defined but never used. Allowed unused vars must match /^_/u.  no-unused-vars
2022-03-07T15:37:11.597Z  3:8  Error: 'Section' is defined but never used. Allowed unused vars must match /^_/u.  no-unused-vars
2022-03-07T15:37:11.597Z  4:10  Error: 'WorkGridItem' is defined but never used. Allowed unused vars must match /^_/u.  no-unused-vars
2022-03-07T15:37:11.598Z  11:28  Error: React Hook "useWeb3Modal" is called in function "mint" that is neither a React function component nor a custom React 
Hook function. React component names must start with an uppercase letter. React Hook names must start with the word "use".  react-hooks/rules-of-hooks       
2022-03-07T15:37:11.598Z
2022-03-07T15:37:11.598Z  ./components/grid-item.js
2022-03-07T15:37:11.598Z  26:5  Warning: passHref is missing. See: https://nextjs.org/docs/messages/link-passhref  @next/next/link-passhref
2022-03-07T15:37:11.598Z
2022-03-07T15:37:11.598Z  ./components/mint.js
2022-03-07T15:37:11.598Z  3:30  Error: 'VStack' is defined but never used. Allowed unused vars must match /^_/u.  no-unused-vars
2022-03-07T15:37:11.598Z  3:52  Error: 'Link' is defined but never used. Allowed unused vars must match /^_/u.  no-unused-vars
2022-03-07T15:37:11.598Z  3:58  Error: 'Text' is defined but never used. Allowed unused vars must match /^_/u.  no-unused-vars
2022-03-07T15:37:11.599Z  3:64  Error: 'Spacer' is defined but never used. Allowed unused vars must match /^_/u.  no-unused-vars
2022-03-07T15:37:11.599Z  5:33  Error: 'IoMdOpen' is defined but never used. Allowed unused vars must match /^_/u.  no-unused-vars
2022-03-07T15:37:11.599Z  8:41  Error: 'loading' is assigned a value but never used. Allowed unused vars must match /^_/u.  no-unused-vars
2022-03-07T15:37:11.599Z  
2022-03-07T15:37:11.599Z  info  - Need to disable some ESLint rules? Learn more here: https://nextjs.org/docs/basic-features/eslint#disabling-rules
2022-03-07T15:37:11.616Z  Error: Command "npm run build" exited with 1
2022-03-07T15:37:12.463Z

现在,只想说我尝试解决警告,我 运行:

npm install uuid

安装最新的uuid版本,这样我就可以绕过第一个警告。但它也没有帮助。我又执行了vercel命令,也有类似的日志。

我试图在vercel 上的项目设置下将构建设置覆盖到CI=False,但仍然没有得到任何成功的响应。

我的 package.json 看起来像这样:

{
  "name": "demo-minting-page",
  "version": "1.0.0",
  "description": "TokenMinds Demo ",
  "scripts": {
    "dev": "next dev -H 0.0.0.0",
    "prettier": "prettier -write .",
    "lint": "next lint",
    "build": "next build",
    "start": "next start"
  },
  "keywords": [],
  "author": "Hemang Joshi",
  "license": "MIT",
  "dependencies": {
    "@chakra-ui/icons": "^1.1.7",
    "@chakra-ui/react": "^1.8.6",
    "@emotion/react": "^11.8.1",
    "@emotion/styled": "^11.8.1",
    "ethers": "^5.5.4",
    "framer-motion": "^6.2.8",
    "merkletreejs": "^0.2.30",
    "react-icons": "^4.3.1",
    "react-toastify": "^8.2.0",
    "three": "^0.138.3",
    "uuid": "^8.3.2",
    "web3": "^1.7.1",
    "web3modal": "^1.9.5",
    "zustand": "^3.7.1"
  },
  "devDependencies": {
    "eslint": "^8.9.0",
    "eslint-config-next": "^12.1.0",
    "prettier": "^2.5.1",
    "webpack": "^5.70.0"
  }
}

.eslintrc.json 看起来像这样:

{
    "root": true,
    "extends": "next",
    "rules": {
       "plugin":[
            
                "react/recommended"
            
       ],
              "no-unused-vars": [
        "error",
        {
          "argsIgnorePattern": "^_",
          "varsIgnorePattern": "^_"
        }
      ],
      "react/display-name": 0
    }
}

Link 我保存此代码的完整 github 存储库是: Github repo

请大家帮帮我,我该怎么办

P.S:- 在我的 localhost:3000 上一切都运行得非常顺利,并且没有任何错误。我现在在我的终端上有好几次 运行 npm run dev,但是在本地主机上没有任何投诉。

有两种方法可以解决这个问题。

  1. 您似乎正在将模块导入到某些js文件中,但并未使用它们,因此请避免使用不必要的导入,并且仅在页面上使用时才导入模块。如果您不使用它,请避免将该模块导入 js 文件。

  1. 安装以下模块npm install --save-dev eslint-plugin-react.(针对使用 NPM 的开发人员)或yarn add --dev eslint-plugin-react.(针对使用 Yarn 的开发人员)

    然后,在您的 .eslintrc.json 的扩展下,包括以下插件:

    'extends': [
        'plugin:react/recommended'
    ]
    

如果您使用以上任何建议,希望您的错误能够得到解决

这里的问题是从未使用过导入的变量。请删除那些未使用的变量,并在您的本地计算机中删除 运行 npm run build 以查看是否遗漏了任何错误。之后你可以重新部署到vercel。