使用 npm run build 在构建中遇到以下问题。在 create-react-app 项目中。
也出现在另一个 nextjs 项目中。
有人对此有任何想法吗?无法在任何地方堆栈跟踪,它似乎来自 babel。
对于 create-react-app 的情况,我无法更改其中的任何 babel 配置。
我使用 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
dependencies typescript reactjs package.json create-react-app
我.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) 所以,我用 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) 紧接着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
我必须将 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} />.
我在我的 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) 我已经找到了一些关于此的帖子,但现有的解决方案似乎都不起作用。
然后尝试使用以下内容启动一个新的 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) 突然出现,这个错误让我跺脚。任何时候我尝试导入 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 上运行得非常好,没问题!
我刚刚使用 create-react-app 工具创建了一个 react typscript 应用程序,我在项目结构中找到了一个名为 react-app-env.d.ts 的文件。我需要知道这个文件的目的是什么
create-react-app ×10
reactjs ×9
javascript ×2
typescript ×2
antd ×1
babeljs ×1
dependencies ×1
eslint ×1
icons ×1
jestjs ×1
node.js ×1
npx ×1
package.json ×1
webpack ×1
yarnpkg ×1