我是新手create-react-app。我想知道为什么打开index.html表单构建不起作用??我知道serve -s build应该使用服务构建,但我想知道为什么构建反应应用程序不能在没有服务的情况下启动。
我将进一步解释:我所做的是......
create-react-app helloworldnpm run build或者yarn run build...现在我将在其中./build创建我的目录index.html。index.html在浏览器中打开它不会工作。我想了解为什么这不起作用?为什么我必须为构建提供服务才能使其工作?
在使用 CRA v.1 创建的应用程序中,我需要运行特定的测试文件。我该怎么做?有一个--testPathIgnorePatterns标志可以添加到npm test脚本中以忽略文件或路径,但是如何从命令行使用 CRA 运行特定的测试文件?
npm run build创建项目的生产版本。我如何创建开发版本?我正在使用gradle-node-plugin来构建工件。该项目具有标准的create-react-app配置。
我正在尝试按照这些说明使用打字稿模板创建一个新项目。
npx create-react-app app-ui --template typescript
Run Code Online (Sandbox Code Playgroud)
尽管它安装了所有节点模块,但它不会创建启动项目,也不会使用提供的模板。我收到这条消息:
A template was not provided. This is likely because you're using an outdated version of create-react-app.
Please note that global installs of create-react-app are no longer supported.
Run Code Online (Sandbox Code Playgroud)
我正在尝试按照说明删除 cli 的全局安装,但这也不起作用:
npm uninstall -g create-react-app
up to date in 0.037s
Run Code Online (Sandbox Code Playgroud)
无论我做什么,我都无法卸载 cli。到底是怎么回事?
编辑:
我能够让它在 PC 上部分工作。
npm remove create-react-app
Run Code Online (Sandbox Code Playgroud)
然后
npx create-react-app my-app [--template typescript]
Run Code Online (Sandbox Code Playgroud)
我尝试使用括号,虽然模板项目在那里,但它不在打字稿中。现在 cli 有问题。
编辑:
这篇文章解决了无法卸载cli的问题。希望这对某人有所帮助,并请为 OP 投票。
我已经升级到最新的 Create React App 4.0。现在scss无法解析公共文件夹中的图像资产。我之前使用的是 CRA 3.4.1。它工作得很好。
有任何想法吗?我不想使用npm eject
icon.svg 在 public/images
background-image: url(/images/icon.svg);
Failed to compile.
./src/Components/style.scss
(./node_modules/css-loader/dist/cjs.js??ref--5-oneOf-6-1!
./node_modules/postcss-loader/src??postcss!
./node_modules/resolve-url-loader??ref--5-oneOf-6-3!
./node_modules/sass-loader/dist/cjs.js??ref--5-oneOf-6-4!
./src/Components/style.scss)
Error: Can't resolve '../../../../../../icon.svg' in ''
Run Code Online (Sandbox Code Playgroud)
在 Create React App 3.x 中,从(S)CSS 中的公共文件夹中引用图像只需使用起始斜杠即可,如已回答here。
正如 OP 所解释的那样,图像在public/images并被引用为url(/images/icon.svg).
这不再适用于 Create React App 4.0.0 并给出错误消息Error: Can't resolve '../../../../../../icon.svg' in ''。Create React App的更新日志没有提到有关公共文件夹的重大更改。
我正在尝试从 DigitalOcean droplet 提供 react-app 的构建文件夹。
After I run yarn build, I get told by the script to run
yarn global add serve
serve -s build
However, when I run serve -s build, It say's it's running on http://localhost:5000. I would like it run on localhost:3000 instead, as I have another server running on port 5000. How can i specify the port number such that serve -s build runs on port 3000?
如何在使用 create-react-app CRA 创建的 React 应用程序的生产版本中删除 console.log?
我正在create-react-app与 TS 一起使用,import type但 eslint 在 VS Code 中抱怨说,Parsing error: '=' expected当悬停type在import type. 我正在使用 eslint,6.7.2
我使用“create-react-app”创建了一个反应应用程序,并且在我的一个项目文件中,我使用了以下导入语句;
import { Icon } from 'antd',
并收到以下错误:
Attempted import error: 'Icon' is not exported from 'antd'.
Run Code Online (Sandbox Code Playgroud)
不知道是什么问题。请帮忙。
在我所有的.ts或.tsx文件,我有像下面的截图文件中的第一个字符这样的警告:
我正在使用标准的 CRA 设置。这是我的package.json:
{
"name": "my-project",
"version": "0.1.0",
"private": true,
"dependencies": {
"firebase": "^8.0.1",
"formik": "^2.2.3",
"i18next": "^19.8.3",
"i18next-browser-languagedetector": "^6.0.1",
"i18next-xhr-backend": "^3.2.2",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-firebaseui": "^4.1.0",
"react-i18next": "^11.7.3",
"react-router-dom": "^5.2.0",
"react-scripts": "^4.0.0",
"react-select": "^3.1.0",
"react-spinners": "^0.9.0",
"react-syntax-highlighter": "^15.3.0",
"react-transition-group": "^4.4.1",
"styled-components": "^5.2.1",
"yup": "^0.29.3"
},
"devDependencies": {
"@cypress/webpack-preprocessor": "^5.4.10",
"@types/firebase": "^3.2.1",
"@types/jest": "^26.0.15",
"@types/react": "^16.9.56",
"@types/react-dom": "^16.9.9",
"@types/react-router-dom": "^5.1.6",
"@types/react-select": "^3.0.23",
"@types/react-syntax-highlighter": "^13.5.0",
"@types/styled-components": "^5.1.4",
"@types/yup": "^0.29.9",
"cypress": "^5.5.0",
"eslint-plugin-cypress": "^2.11.2", …Run Code Online (Sandbox Code Playgroud) create-react-app ×10
reactjs ×6
antd ×1
build ×1
console.log ×1
eslint ×1
node.js ×1
npm ×1
typescript ×1
unit-testing ×1
webpack ×1
yarnpkg ×1