使用Tailwind和AOS部署React

如何解决使用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

这里是Netlify article

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 <select id="xxx"> SELECT di.id, di.name, di.work_type, di.updated... <where> <if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 <property name="dynamic.classpath" value="tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams['font.sans-serif'] = ['SimHei'] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -> systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping("/hires") public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate<String
使用vite构建项目报错 C:\Users\ychen\work>npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-