如何解决使用Tailwind和AOS部署React
我用React Tailwind template建立了一个网站。它在我的浏览器中完美运行。 npm start不会有任何问题。但是,当我尝试部署到Netlify或Heroku时,出现错误。我已经仔细阅读了文档,并尝试了许多不同的教程,但无济于事。
当我运行npm run build时,在本地出现错误。
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! react-landing-page@0.1.0 build: `react-scripts build && gulp licenses`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the react-landing-page@0.1.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
我进入package.json并删除了脚本的一部分。
我改变了
"build": "react-scripts build && gulp licenses"
对此:
"build": "react-scripts build"
只是测试一下。它消除了本地错误,但是当我尝试部署时却没有。这是来自Netlify的错误,在任何一个脚本中都没有改变。
我还尝试了从我的linux机器上运行npm run build,并得到了相同的结果。
'''
2:50:45 PM: Build ready to start
2:50:47 PM: build-image version: b0258b965567defc4a2d7e2f2dec2e00c8f73ad6
2:50:47 PM: build-image tag: v3.4.1
2:50:47 PM: buildbot version: c6376102eedf4be6c6e5d685c7141e2eb612d47d
2:50:47 PM: Fetching cached dependencies
2:50:47 PM: Failed to fetch cache,continuing with build
2:50:47 PM: Starting to prepare the repo for build
2:50:48 PM: No cached dependencies found. Cloning fresh repo
2:50:48 PM: git clone https://github.com/MichaelMacaulay/testing
2:50:49 PM: Preparing Git Reference refs/heads/main
2:50:51 PM: Different publish path detected,going to use the one specified in the Netlify configuration file: 'build' versus 'build/' in the Netlify UI
2:50:51 PM: Starting build script
2:50:51 PM: Installing dependencies
2:50:51 PM: Python version set to 2.7
2:50:52 PM: v12.18.0 is already installed.
2:50:53 PM: Now using node v12.18.0 (npm v6.14.4)
2:50:53 PM: Started restoring cached build plugins
2:50:53 PM: Finished restoring cached build plugins
2:50:53 PM: Attempting ruby version 2.7.1,read from environment
2:50:55 PM: Using ruby version 2.7.1
2:50:55 PM: Using PHP version 5.6
2:50:55 PM: 5.2 is already installed.
2:50:55 PM: Using Swift version 5.2
2:50:55 PM: Started restoring cached node modules
2:50:55 PM: Finished restoring cached node modules
2:50:56 PM: Installing NPM modules using NPM version 6.14.4
2:51:35 PM: > core-js@2.6.11 postinstall /opt/build/repo/node_modules/babel-runtime/node_modules/core-js
2:51:35 PM: > node -e "try{require('./postinstall')}catch(e){}"
2:51:35 PM: > core-js@3.6.5 postinstall /opt/build/repo/node_modules/core-js
2:51:35 PM: > node -e "try{require('./postinstall')}catch(e){}"
2:51:38 PM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.1.3 (node_modules/watchpack/node_modules/fsevents):
2:51:38 PM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
2:51:38 PM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules/chokidar/node_modules/fsevents):
2:51:38 PM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"x64"})
2:51:38 PM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules/jest-haste-map/node_modules/fsevents):
2:51:38 PM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"x64"})
2:51:38 PM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.0.7 (node_modules/fsevents):
2:51:38 PM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.0.7: wanted {"os":"darwin","arch":"x64"})
2:51:38 PM: added 1745 packages from 778 contributors and audited 1752 packages in 41.328s
2:51:40 PM: 57 packages are looking for funding
2:51:40 PM: run `npm fund` for details
2:51:40 PM: found 5 vulnerabilities (1 low,2 moderate,2 high)
2:51:40 PM: run `npm audit fix` to fix them,or `npm audit` for details
2:51:40 PM: NPM modules installed
2:51:40 PM: Started restoring cached go cache
2:51:40 PM: Finished restoring cached go cache
2:51:40 PM: go version go1.14.4 linux/amd64
2:51:40 PM: go version go1.14.4 linux/amd64
2:51:40 PM: Installing missing commands
2:51:40 PM: Verify run directory
2:51:42 PM:
2:51:42 PM: ┌─────────────────────────────┐
2:51:42 PM: │ Netlify Build │
2:51:42 PM: └─────────────────────────────┘
2:51:42 PM:
2:51:42 PM: ❯ Version
2:51:42 PM: @netlify/build 4.8.1
2:51:42 PM:
2:51:42 PM: ❯ Flags
2:51:42 PM: deployId: 5f7e0e056fc9cb00899b6282
2:51:42 PM: mode: buildbot
2:51:42 PM:
2:51:42 PM: ❯ Current directory
2:51:42 PM: /opt/build/repo
2:51:42 PM:
2:51:42 PM: ❯ Config file
2:51:42 PM: No config file was defined: using default values.
2:51:42 PM:
2:51:42 PM: ❯ Context
2:51:42 PM: production
2:51:42 PM:
2:51:42 PM: ┌───────────────────────────────────┐
2:51:42 PM: │ 1. Build command from Netlify app │
2:51:42 PM: └───────────────────────────────────┘
2:51:42 PM:
2:51:42 PM: $ npm run build
2:51:42 PM: > react-landing-page@0.1.0 build /opt/build/repo
2:51:42 PM: > react-scripts build && gulp licenses
2:51:44 PM: Creating an optimized production build...
2:51:57 PM:
2:51:57 PM: Treating warnings as errors because process.env.CI = true.
2:51:57 PM: Most CI servers set it automatically.
2:51:57 PM:
2:51:57 PM: Failed to compile.
2:51:57 PM:
2:51:57 PM: ./src/components/Navbar.js
2:51:57 PM: Line 17:13: The href attribute is required for an anchor to be keyboard accessible. Provide a valid,navigable address as the href value. If you cannot provide an href,but still need the element to resemble a link,use a button and change it with appropriate styles. Learn more: https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/anchor-is-valid.md jsx-a11y/anchor-is-valid
2:51:57 PM: ./src/components/Footer.js
2:51:57 PM: Line 73:23: The href attribute is required for an anchor to be keyboard accessible. Provide a valid,use a button and change it with appropriate styles. Learn more: https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/anchor-is-valid.md jsx-a11y/anchor-is-valid
2:51:57 PM: Line 78:23: The href attribute is required for an anchor to be keyboard accessible. Provide a valid,use a button and change it with appropriate styles. Learn more: https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/anchor-is-valid.md jsx-a11y/anchor-is-valid
2:51:57 PM: Line 83:23: The href attribute is required for an anchor to be keyboard accessible. Provide a valid,use a button and change it with appropriate styles. Learn more: https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/anchor-is-valid.md jsx-a11y/anchor-is-valid
2:51:57 PM: Line 88:23: The href attribute is required for an anchor to be keyboard accessible. Provide a valid,use a button and change it with appropriate styles. Learn more: https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/anchor-is-valid.md jsx-a11y/anchor-is-valid
2:51:57 PM: Line 103:17: The href attribute is required for an anchor to be keyboard accessible. Provide a valid,use a button and change it with appropriate styles. Learn more: https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/anchor-is-valid.md jsx-a11y/anchor-is-valid
2:51:57 PM: npm ERR! code ELIFECYCLE
2:51:57 PM: npm ERR! errno 1
2:51:57 PM: npm ERR! react-landing-page@0.1.0 build: `react-scripts build && gulp licenses`
2:51:57 PM: npm ERR! Exit status 1
2:51:57 PM: npm ERR!
2:51:57 PM: npm ERR! Failed at the react-landing-page@0.1.0 build script.
2:51:57 PM: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2:51:57 PM: npm ERR! A complete log of this run can be found in:
2:51:57 PM: npm ERR! /opt/buildhome/.npm/_logs/2020-10-07T18_51_57_432Z-debug.log
2:51:57 PM:
2:51:57 PM: ┌─────────────────────────────┐
2:51:57 PM: │ "build.command" failed │
2:51:57 PM: └─────────────────────────────┘
2:51:57 PM:
2:51:57 PM: Error message
2:51:57 PM: Command failed with exit code 1: npm run build
2:51:57 PM:
2:51:57 PM: Error location
2:51:57 PM: In Build command from Netlify app:
2:51:57 PM: npm run build
2:51:57 PM:
2:51:57 PM: Resolved config
2:51:57 PM: build:
2:51:57 PM: command: npm run build
2:51:57 PM: commandOrigin: ui
2:51:57 PM: publish: /opt/build/repo/build
2:51:57 PM: Caching artifacts
2:51:57 PM: Started saving node modules
2:51:57 PM: Finished saving node modules
2:51:57 PM: Started saving build plugins
2:51:57 PM: Finished saving build plugins
2:51:57 PM: Started saving pip cache
2:51:57 PM: Finished saving pip cache
2:51:57 PM: Started saving emacs cask dependencies
2:51:57 PM: Finished saving emacs cask dependencies
2:51:57 PM: Started saving maven dependencies
2:51:57 PM: Finished saving maven dependencies
2:51:57 PM: Started saving boot dependencies
2:51:57 PM: Finished saving boot dependencies
2:51:57 PM: Started saving go dependencies
2:51:57 PM: Finished saving go dependencies
2:52:00 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
2:52:00 PM: Failing build: Failed to build site
2:52:00 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2
2:52:00 PM: Finished processing build request in 1m13.332194271s
以下是当前Github repo.的链接,我们非常感谢您的帮助。几天来一直在努力挣扎。
解决方法
它在本地工作但不在Netlify上部署的原因是在这里写:D
2:51:57 PM: Treating warnings as errors because of process.env.CI = true.
2:51:57 PM: Most CI servers set it automatically.
2:51:57 PM:
2:51:57 PM: Failed to compile.
2:51:57 PM:
2:51:57 PM: ./src/components/Navbar.js
2:51:57 PM: Line 17:13: The href attribute is required for an anchor to be keyboard
您有一些警告(VSCode中的黄色下划线)被视为错误(红色下划线),并且错误阻止了构建过程。
在本地,您没有此环境变量(CI
设置为true)
要解决此问题,请修复代码中的所有警告,或将其添加到您的Netlify build command:
CI='' npm run build
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。