Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Minified React error #321; visit https://reactjs.org/docs/error-decoder.html?invariant=321

I am trying to create few react components with few custom changes as package and publish into npm so that other projects can use them by importing package.

My package is "sample-testing" available at (https://www.npmjs.com/package/sample-testing).

Using "webpack" and "babel loader" to traslate the jsx files.

Getting below error when I tried to use that component from this package.

Minified React error #321; visit https://reactjs.org/docs/error-decoder.html?invariant=321 for the full message or use the non-minified dev environment for full errors and additional helpful warnings.

This error is coming only when I used material ui components inside package but not with regular html components.

.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;

Here is the codesandbox link (https://codesandbox.io/s/xenodochial-mcclintock-xtkh6?file=/src/index.js) to replicate the error which I am getting in my project when I used in my project. Please help me to resolve it.

like image 319
HimaaS Avatar asked May 13 '20 10:05

HimaaS


People also ask

What is Minified error in React?

In the minified production build of React, they avoid sending down full error messages. Instead, we can use the error code to view the full message for full errors and additional helpful warnings. This small tool is meant to mitigate this gap.

What is Minified React Error #152?

The error description is here, you return nothing as result of render method of you react component. Return something else instead of it.

What is Minified React Error #185?

#185 text: Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate. React limits the number of nested updates to prevent infinite loops.

What is React error?

Error boundaries are React components that catch JavaScript errors anywhere in their child component tree, log those errors, and display a fallback UI instead of the component tree that crashed. Error boundaries catch errors during rendering, in lifecycle methods, and in constructors of the whole tree below them.


1 Answers

One reason could be you are importing useEffect from the wrong place (probably the IDE did it)

Wrong

import {useEffect} from "react/cjs/react.production.min";

OK

import React, {useEffect} from 'react';
like image 107
Juanma Menendez Avatar answered Sep 17 '22 14:09

Juanma Menendez