标签: create-react-app

错误:[BABEL] /home/vsts/work/1/s/src/index.js:找不到模块“./src/data”

使用 npm run build 在构建中遇到以下问题。在 create-react-app 项目中。

也出现在另一个 nextjs 项目中。

有人对此有任何想法吗?无法在任何地方堆栈跟踪,它似乎来自 babel。

对于 create-react-app 的情况,我无法更改其中的任何 babel 配置。

babeljs create-react-app

8
推荐指数
0
解决办法
298
查看次数

为什么 create-react-app 将类型和打字稿放在依赖项而不是开发依赖项中?

我使用 create-react-app 创建了一个 react-typescript 项目。我看到 package.json 如下所示:

"dependencies": {
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.4.0",
    "@testing-library/user-event": "^7.2.1",
    "@types/jest": "^24.9.1",
    "@types/node": "^12.12.26",
    "@types/react": "^16.9.19",
    "@types/react-dom": "^16.9.5",
    "react": "^16.12.0",
    "react-dom": "^16.12.0",
    "react-scripts": "3.3.1",
    "typescript": "^3.7.5"
  },
Run Code Online (Sandbox Code Playgroud)

*

没有 dev-dependencies 部分,为什么它将 typescript(和 @types)放在 dependencies 部分?不仅如此,官方的 create-react-app 页面也会安装没有 -D/save-dev 标志的类型/打字稿。如果消费者在使用我的包时可能会依赖某些类型作为重复问题的建议,为什么这种行为不是每个地方都默认?我在这里缺少什么?官方文档中没有提到这一点。甚至打字稿文档将其安装为 save-dev。 https://www.typescriptlang.org/docs/handbook/react-&-webpack.html

* 官方链接https://create-react-app.dev/docs/adding-typescript/

dependencies typescript reactjs package.json create-react-app

8
推荐指数
0
解决办法
1668
查看次数

create-react-app — 如何将 EXTEND_ESLINT 设置为 true?

我.env在我的项目根目录中创建了一个文件,但我不熟悉环境/变量,所以我不确定如何集成该文件,以便我可以覆盖库存的、未弹出的 react-app eslint 设置。

// My .env file has just this

EXTEND_ESLINT = "true"
Run Code Online (Sandbox Code Playgroud)

该CRA文档解释变量是什么,但不是现在把它设置为true。此外,“扩展 ESLint 配置”部分仅在 var 设置为 true 时有用。

// stock create-react-app package.json

"scripts": {
  "start": "react-scripts start",
  "build": "react-scripts build",
  "test": "react-scripts test",
  "eject": "react-scripts eject"
},
Run Code Online (Sandbox Code Playgroud)

environment-variables reactjs eslint create-react-app

8
推荐指数
2
解决办法
9245
查看次数

功能组件渲染一次,类组件渲染两次

所以,我用 create-react-app 开始了这个新项目(它运行的是 react v.16.13.1)。我把基础App组件改写成一个类,发现当组件是函数的时候,像这样:

function App() {
  console.log('App (function)');
  return 'App (function)';
}
Run Code Online (Sandbox Code Playgroud)

浏览器控制台打印出来

App (function)
Run Code Online (Sandbox Code Playgroud)

万分感谢!但是如果同一个 App 组件写成

class App extends React.Component {
  render() {
    console.log('App (class)');
    return 'App (class)';
  }
}
Run Code Online (Sandbox Code Playgroud)

控制台写入

App (class)
App (class)
Run Code Online (Sandbox Code Playgroud)

javascript reactjs create-react-app

8
推荐指数
1
解决办法
1177
查看次数

在 npm create-react-app 之后立即运行测试非常慢

紧接着npx create-react-app my-app,我进入my-app文件夹并执行CI=true npm test。

结果输出是:

> react-scripts test

PASS src/App.test.js
  ? renders learn react link (39ms)

Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        4.465s
Ran all test suites.
Run Code Online (Sandbox Code Playgroud)

在package.json将标志添加--env=jsdom到 后react-scripts test,我得到:

PASS src/App.test.js
  ? renders learn react link (42ms)

Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        2.026s, estimated 3s
Ran all …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs jestjs create-react-app react-testing-library

8
推荐指数
1
解决办法
267
查看次数

v4 中来自字符串的 Antd 图标类型

我必须将 antd 从 v3 升级到 v4,以前我们用来显示一些来自作为 prop 传递的字符串的图标,如下所示:

 <Icon type={props.icon} />
Run Code Online (Sandbox Code Playgroud)

有没有办法使用新的 Icon 系统在 antd v4 中实现这样的目标?我知道存在 '@ant-design/compatible' 但迁移是为了减少包大小,所以我想避免这个解决方案。

编辑:我只是改变了我使用图标的方式,在我的配置文件中,我导入了图标并将它们传递给我的生成器,就像这样:icon = {props.icon}而不是之前的<Icon type={props.icon} />.

icons reactjs create-react-app antd

8
推荐指数
2
解决办法
2599
查看次数

create-react-app 时发生意外错误:“https://registry.yarnpkg.com/react:无法获取本地颁发者证书”

我在我的 Windows 机器上安装了以下内容:

节点:v12.18.4

纱线:1.19.1

创建反应应用程序:3.4.1

我导航到文件夹 c:\temp,然后尝试使用以下命令创建 react 应用程序:

c:\temp>create-react-app react-test --scripts-version 1.1.5

在执行上述命令时,我看到以下错误:

Creating a new React app in C:\Temp\react-test.

Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts with cra-template...

yarn add v1.19.1
[1/4] Resolving packages...
error An unexpected error occurred: "https://registry.yarnpkg.com/react: unable to get local issuer certificate".
info If you think this is a bug, please open a bug report with the information provided in "C:\\Temp\\react-test\\yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/add for documentation …
Run Code Online (Sandbox Code Playgroud)

node.js reactjs create-react-app yarnpkg

8
推荐指数
2
解决办法
4912
查看次数

npx create-react-app 在 big sur 上执行 yarnpkg 时失败

我已经找到了一些关于此的帖子,但现有的解决方案似乎都不起作用。

  • OSX 大苏尔
  • 纱线 1.22.10
  • npm 7.0.11
  • 我更新了 xcode 开发人员工具。
  • 我删除了 npm 缓存
  • 我删除了 .npm 和 .yarnrc 文件夹

然后尝试使用以下内容启动一个新的 React 应用程序npx create-react-app:

error An unexpected error occurred: "expected workspace package to exist for \"eslint\"".
info If you think this is a bug, please open a bug report with the information provided in "/Users/gdboling/Projects/BalancedComp/clients/packages/rewards/yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.

Aborting installation.
  yarnpkg add --exact react react-dom react-scripts cra-template --cwd /Users/gdboling/Projects/BalancedComp/clients/packages/rewards has failed.
Run Code Online (Sandbox Code Playgroud)

日志文件有:

26 verbose stack …
Run Code Online (Sandbox Code Playgroud)

reactjs create-react-app npx macos-big-sur

8
推荐指数
1
解决办法
2582
查看次数

Create-react-app '编译失败。由于 css 导入

突然出现,这个错误让我跺脚。任何时候我尝试导入 css 文件时都会出现,无论是完整的还是作为模块的。

例如

import "./index.css"
Run Code Online (Sandbox Code Playgroud)

或者

import styles from "./button.module.css"
Run Code Online (Sandbox Code Playgroud)

这可能是由于最新的 macOS 测试版,至少它似乎与它的发布相吻合。我尝试从它回滚,但这没有用。

Failed to compile
./src/index.css (./node_modules/css-loader/dist/cjs.js?modules=true!./node_modules/style-loader/dist/cjs.js!./node_modules/css-loader/dist/cjs.js??ref--6-oneOf-4-1!./node_modules/postcss-loader/src??postcss!./src/index.css)
CssSyntax error: Unknown word (1:1)

> 1 | var api = require("!../node_modules/style-loader/dist/runtime/injectStylesIntoStyleTag.js");
    | ^
  2 |             var content = require("!!../node_modules/css-loader/dist/cjs.js??ref--6-oneOf-4-1!../node_modules/postcss-loader/src/index.js??postcss!./index.css");
  3 | 
This error occurred during the build time and cannot be dismissed.
Run Code Online (Sandbox Code Playgroud)

我试过手动添加 web pack,检查所有语法错误,重新安装整个 repo,返回几次提交等等。似乎什么都做不了。很高兴提供更多背景信息。

(我在 15 小时前发现另一个人在 SO 上提到了同样的问题,但他没有提供调试信息,所以票被关闭了)。

注意:相同的代码库在我的 MacBook 上运行得非常好,没问题!

reactjs webpack create-react-app

8
推荐指数
1
解决办法
270
查看次数

react typescript 项目中的 react-app-env.d.ts 是什么

我刚刚使用 create-react-app 工具创建了一个 react typscript 应用程序,我在项目结构中找到了一个名为 react-app-env.d.ts 的文件。我需要知道这个文件的目的是什么

typescript reactjs create-react-app

8
推荐指数
2
解决办法
5010
查看次数