我的控制台一直说“要设置编辑器集成,请将 REACT_EDITOR=atom 之类的内容添加到项目文件夹中的 .env.local 文件并重新启动开发服务器。了解更多信息”
我什至无法在我的 create-react-app 上找到 .env 文件。
先感谢您。
这是反应组件类中的一些代码(使用 CRA 2 搭建)
click = () => {
console.log(this, "hello");
let x = 1 + 1; //This is just here to let chrome put a break point here.
}
Run Code Online (Sandbox Code Playgroud)
当此代码运行时,它会将组件对象打印到控制台。
但是 - 如果我将调试器附加到该点,Chrome (68) 和 Firefox (63) 都会将“this”显示为未定义。
这里发生了什么?
是否与用于将点击创建为类属性的 transform-class-properties babel 插件有关?
编辑: 是的,这似乎正是它的样子。
如果我们手动绑定方法,如:
constructor() {
super();
this.click2 = this.click2.bind(this);
}
click2() {
console.log(this, "hello");
let x = 1 + 1;
}
Run Code Online (Sandbox Code Playgroud)
然后它工作正常。
在任何情况下 - 有没有一种方便的方法来解决这个问题,所以我不必把所有这些绑定语句都放进去?
所以我有 JSON 数据,其中包括位于我的公共文件夹 (/public/images) 中的图像的路径。像这样,
const data = [
{
"key": 1,
"name": "Goal Squad",
"techs": ["React & Redux", "Express", "MySQL"],
"description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et",
"image": "../public/images/test.jpg"
},
{
"key": 2,
"name": "WesterosCraft",
"techs": ["React & Redux", "Express", "MySQL"],
"description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et",
"image": "../public/images/test.jpg"
},
Run Code Online (Sandbox Code Playgroud)
根据阅读其他一些类似情况,这就是我在我的组件中尝试过的;
class Card extends Component {
render() { …Run Code Online (Sandbox Code Playgroud) 如何在 Babel 7 中禁用 --isolatedModules 标志,它会导致一切崩溃。它崩溃于:
我的 webpack 配置删除了导入以达到字数限制。我试过在我的 tsconfig 中禁用它,但我认为 babel 忽略了它。
'use strict';
// Source maps are resource heavy and can cause out of memory issue for large source files.
const shouldUseSourceMap = process.env.GENERATE_SOURCEMAP !== 'false';
// Some apps do not need the benefits of saving a web request, so not inlining the chunk
// makes for a smoother build process.
const shouldInlineRuntimeChunk = process.env.INLINE_RUNTIME_CHUNK !== 'false';
// Check if TypeScript is setup …Run Code Online (Sandbox Code Playgroud)我是 create-react-app 的新手。
我刚刚用 redux 和 react-router-dom 做了一个新的设置,然后将它推送到 Scalingo,然后是 Heroku,它们最终都为开发构建服务。我的 redux-logger 已开启,React 开发工具警告说:
此页面使用 React 的开发版本。
我没有做任何定制部署,只是推到生产。
我究竟做错了什么 ?
Scalingo 部署日志:
<-- Start deployment of ***** -->
Fetching source code
Fetching deployment cache
-----> Creating runtime environment
NPM_CONFIG_LOGLEVEL=error
NPM_CONFIG_PRODUCTION=true
NODE_VERBOSE=false
NODE_ENV=production
NODE_MODULES_CACHE=true
-----> Installing binaries
engines.node (package.json): unspecified
engines.npm (package.json): unspecified (use default)
engines.yarn (package.json): unspecified (use default)
Resolving node version 8.x...
Downloading and installing node 8.15.0...
Using default npm version: 6.4.1
Resolving yarn version 1.x...
Downloading and installing yarn …Run Code Online (Sandbox Code Playgroud) 我试图通过消除不必要的图标来减小Ant Design库的大小。我在网上找到了这个解决方案,https://github.com/ant-design/ant-design/issues/12011#issuecomment-423173228
解决方案包括像这样配置 Webpack:
module.exports = {
//...
resolve: {
alias: {
"@ant-design/icons/lib/dist$": path.resolve(__dirname, "./src/icons.js")
}
}
};
Run Code Online (Sandbox Code Playgroud)
我不知道如何做到这一点,因为我使用react-app-rewired,并customize-cra伴随着babel-plugin-import,所以我的“配置- overrides.js”文件是这样的,这是从提供的例子非常不同。
const { override, fixBabelImports } = require('customize-cra');
module.exports = override(
fixBabelImports('import', {
libraryName: 'antd',
style: 'css',
}),
);
Run Code Online (Sandbox Code Playgroud)
我正在使用以下依赖项:
"antd": "^3.14.1",
"babel-plugin-import": "^1.11.0",
"customize-cra": "^0.2.12",
"downshift": "^3.2.6",
"material-icons-react": "^1.0.4",
"react": "^16.8.3",
"react-app-rewired": "^2.1.0",
"react-dom": "^16.8.3",
"react-scripts": "^2.1.5",
"styled-components": "^4.1.3"
Run Code Online (Sandbox Code Playgroud)
这看起来与 Github 问题中的示例非常不同。如何向“config-overrides.js”文件添加别名?
我尝试在我的项目中使用 css 模块。我正在使用最新的 Create React App 和 react-scripts 版本 2.1.8。在文档中,它说我可以添加 CSS 模块,而且我不必执行弹出脚本。
我试图以同样的方式做,但我的样式是空的,类是未定义的。这是我的组件之一的代码:
import React, { Component } from 'react';
import styles from './Catalog.css';
class Catalog extends Component{
render() {
console.log('styles.catalog '+ styles.catalog); //returns: styles.catalog undefined.
return (
<div className={styles.catalog}> //returns: <div>
...
</div>
)
}
Run Code Online (Sandbox Code Playgroud)
目录.css:
.catalog {
min-width: 800px;
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试Jest在create-react-app使用override函数 fromcustomize-cra和 的a中设置测试react-app-rewired。我已经设置了一个相对路径别名,当我运行测试时它抛出错误cannot find module
这是代码...
// LoginForm.test.js
import React from 'react';
import { render, fireEvent } from '@testing-library/react';
import LoginForm from './LoginForm';
it('submits', () => {
const onSubmit = jest.fn();
const { getByText } = render(<LoginForm onSubmit={onSubmit} />);
fireEvent.click(getByText('Log in'));
expect(onSubmit).toHaveBeenCalled();
});
Run Code Online (Sandbox Code Playgroud)
// config-overrides.js
const {
override,
fixBabelImports,
addLessLoader,
addBabelPlugin
} = require("customize-cra");
module.exports = override(
fixBabelImports("import", [
{
libraryName: "antd",
libraryDirectory: "es"
// style: true,
},
{ …Run Code Online (Sandbox Code Playgroud) 我正在使用最近的 create-react-app 设置和 JS 和mobx decorate方法。
import { observable, action, decorate } from 'mobx'
class UserStore {
users = []
currentUser = {}
setUsers(value) {
this.users = value
}
}
decorate(UserStore, {
users: observable,
currentUser: observable,
setUsers: action
})
export default UserStore
Run Code Online (Sandbox Code Playgroud)
我可以使用商店并读取空的users和currentUser可观察的,但是当我尝试使用该setUsers操作时,我收到以下错误:
TypeError: Cannot set property 'users' of undefined
它看起来像this未定义,但这是大多数 MobX 教程显示的常见方式,不应抛出错误......
我有一个手风琴,当我点击标题时会打开。我还添加了一个人字形,当它打开时我想改变方向。我不确定如何使用手风琴来做到这一点,因为我不会根据按钮点击来改变状态。我的手风琴代码:
<Accordion defaultActiveKey="0">
<Card>
<Accordion.Toggle as={Card.Header} eventKey="1">
Roll History <FaChevronDown />
</Accordion.Toggle>
<Accordion.Collapse eventKey="1">
<Card.Body>{historyText}</Card.Body>
</Accordion.Collapse>
</Card>
</Accordion>
Run Code Online (Sandbox Code Playgroud)
当手风琴打开时,我想改为显示 FaChevronUp?
create-react-app ×10
reactjs ×8
javascript ×4
webpack ×3
babeljs ×2
browser ×1
css-modules ×1
debugging ×1
heroku ×1
image ×1
jestjs ×1
mobx ×1
mobx-react ×1
typescript ×1