reactjs - 缩小反应错误 #321;访问 https://reactjs.org/docs/error-decoder.html?invariant=321
问题描述
我正在尝试创建一些带有少量自定义更改的反应组件作为包并发布到 npm 中,以便其他项目可以通过导入包来使用它们。
我的包是“sample-testing”,可在(https://www.npmjs.com/package/sample-testing)获得。
使用“webpack”和“babel loader”来翻译 jsx 文件。
当我尝试使用此包中的该组件时出现以下错误。
缩小反应错误 #321;访问https://reactjs.org/docs/error-decoder.html?invariant=321获取完整消息,或使用非缩小开发环境获取完整错误和其他有用的警告。
仅当我在包内使用材料 ui 组件而不是常规 html 组件时才会出现此错误。
.babelrc
{
"presets": ["react", "env", "stage-0"]
}
wepack.config.js
var path = require("path");
module.exports = {
mode: "production",
entry: {
TButton: "./src/TButton.jsx"
},
output: {
path: path.resolve("lib"),
filename: "[name].js",
libraryTarget: "commonjs2"
},
module: {
rules: [
{
test: /\.jsx?$/,
exclude: /(node_modules)/,
use: "babel-loader"
}
]
}
};
TButton.jsx
import React from "react";
import TextField from "@material-ui/core/TextField";
class TButton extends React.Component {
constructor(props) {
super(props);
}
render() {
return <TextField id="standard-basic" label="Standard" />;
}
}
export default TButton;
这是代码和框链接(https://codesandbox.io/s/xenodochial-mcclintock-xtkh6?file=/src/index.js),用于复制我在项目中使用时遇到的错误。请帮我解决它。
解决方案
一个原因可能是您useEffect
从错误的地方导入(可能是 IDE 做到了)
错误的
import {useEffect} from "react/cjs/react.production.min";
好的
import React, {useEffect} from 'react';
推荐阅读
- javascript - 在 render() 之前加载图像
- algorithm - 他们是如何找到以下代码的下界的?
- php - 通过 imap_search() 获取新邮件
- jquery - 在 Woocommerce 中悬停时翻转产品图像
- python - Python SDF 阅读器失败
- javascript - 将 cryto.generateKeyPair 与 jsonwebtoken 一起使用
- c# - 在没有视图的情况下执行 Web 控制器操作 [c#]
- python - 无法为 fasttext 加载输入数据
- ios - 为什么这是一个保留周期?
- wordpress - WordPress metabox - 可编辑的 div 作为输入