Encountering the error "ReferenceError: __extends is not defined" is a common issue when modifying the rollup.config.js commonjs function in projects that use the ReactJS library

Currently, I am involved in a project and there is also a library project containing all the common components used throughout. Within this library, I had to integrate a component that relies on materialUI. However, upon trying to export this component, I encountered the following error:

[!] Error: 'ForwardRef' is not exported by node_modules\react-is\index.js
https://github.com/rollup/rollup/wiki/Troubleshooting#name-is-not-exported-by-module
node_modules\@material-ui\utils\esm\getDisplayName.js (2:9)
1: import _typeof from "@babel/runtime/helpers/esm/typeof";
2: import { ForwardRef, Memo } from 'react-is'; // Simplified polyfill for IE 11 support

To resolve this issue, I made adjustments to the commonjs function within rollup.config.js like so:

commonjs({
      include: "node_modules/**",
      namedExports: {
        "node_modules/react-is/index.js": ["ForwardRef", "Memo"],
      },
    }),

However, this led to another error. Upon reinstalling the library in the main project from scratch, a new error occurs.

   Uncaught ReferenceError: _extends is not defined
at exactProp (index.es.js:14590)
at Module.<anonymous> (index.es.js:18939)
at Module../node_modules/bt-react-lib/dist/index.es.js (index.es.js:25529)
at __webpack_require__ (bootstrap:782)
at fn (bootstrap:150)
at Module../src/components/main/Main.js (Dashboard.js:52)
at __webpack_require__ (bootstrap:782)
at fn (bootstrap:150)
at Module../src/App.js (log$:24)
at __webpack_require__ (bootstrap:782)
at fn (bootstrap:150)
at Module../src/index.js (index.css?02e3:45)
at __webpack_require__ (bootstrap:782)
at fn (bootstrap:150)
at Object.1 (objects.js:1)
at __webpack_require__ (bootstrap:782)
at checkDeferredModules (bootstrap:45)
at Array.webpackJsonpCallback [as push] (bootstrap:32)
at main.chunk.js:1

It seems like another issue related to materialUI. Has anyone encountered this problem before?

Answer №1

Consider treating material as a peer dependency alongside react and react dom. Take a look at this boilerplate for guidance on how to handle this situation.

To start, update your package.json file by moving material to

"peerDependencies": {... }
. Next, make sure to install rollup-plugin-peer-deps-external and include it in your rollup configuration. Once you've completed this step, you can revert the named exports and everything should be good to go.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Production pages encounter 'get' error when refreshed due to routing issues - Node.js, Express API with webpack and ReactJS frontend

I have set up my webpack configuration to compile my react app, and I am using Node.js as the server with Express middleware. Whenever I try to refresh a route on the production environment, for example /chefs, I receive an error. Below is my server.js s ...

Is it possible for an image to be displayed in another div or table column when I hover my mouse over it?

I am looking to create an image gallery with thumbnails on the left side. When I hover over a thumbnail, I want the full image to be displayed in another section on the page. Can anyone provide me with the correct code or suggest a plugin to achieve this f ...

What is the process of relocating JSON and JS code from within an HTML file to external files?

My goal is to separate JSON and JavaScript code from the HTML file by moving them into external files. The examples shown below were part of a test I conducted to verify that the data was being successfully imported. As I begin to include real data, the J ...

Novice in AngularJS routing

Having trouble with my first AngularJS routing code. The error console isn't much help. Here is my HTML page: <body ng-app="myApp"> <div ng-controller="AppController"> <div class="nav"> <ul> <li> ...

Leveraging HTML tables for input purposes

Just starting out with php, HTML, and mysql. Using HTML tables for the first time here. Created an HTML table filled with data from a MySQL table. Planning to use this table as a menu where users can click on a cell with a specific date. The clicked date ...

Error: There was an issue registering the component as the target container is not recognized as a valid DOM element

Upon executing the React code below, I encountered the following error: import React from 'react'; import ReactDOM from 'react-dom'; ReactDOM.render( <div id="root"> <h1>Hello, world!</h1></div>, document ...

Implementing Twitter Login with Vue, Vuex, and Firebase

Exploring a Twitter login option for my sports social media dashboard project, I followed a helpful tutorial. While I've successfully implemented the HelloWorld component and retained the app.vue and main.js components, I encountered an error stating ...

Background styling for TreeItems in Material-UI's TreeView

Just recently, I encountered an interesting phenomenon while working with the following dependencies: "@material-ui/core": "4.8.3", "@material-ui/lab": "4.0.0-alpha.37" After deselecting a TreeItem and selecting another one, I noticed that there was no lo ...

Checking whether a node stream operates in objectMode

When working with a node js stream object, how can I ascertain if it is an object stream in objectMode? For example, suppose I have a readable stream instance: const myReadableStream = new ReadableStreamImplementation({ options: { objectMode : true } ...

Can the child component ensure that the Context value is not null?

In the process of developing a Next.js/React application with TypeScript, I've implemented a UserContext in pages/_app.js that supplies a user: User | null object to all child components. Additionally, there's a ProtectedRoute component designed ...

What is the most effective method for displaying two external web pages next to each other?

Looking for a solution to display an English Wikipedia article on the left side of the page alongside its Spanish version on the right side. Wondering if it's possible using HTML, JavaScript, AJAX, etc. I am aware that I could use iframes, but I woul ...

Using the Play framework to showcase data in an HTML table

I have a project where I am working with multiple tables, one of which is a Person table containing id and name attributes. I have successfully retrieved the data from the database using MySql and converted it into JSON. However, I am struggling to find a ...

Looking for assistance with Redux and React Hooks - anyone?

I have created an interactive image gallery where users can click between page one and page two. When a user clicks on an image, a modal will appear displaying the selected image along with its title and description. There is also a Submit Button that allo ...

Dimensions in Material UI

As I embark on my journey with Material UI components for React, I am facing the challenge of integrating pre-styled components into my project. I have noticed that some components appear too large in my layout due to excessive padding and margins. Curren ...

Tips on customizing image borders/masks with hover effects

Is there a React library or a simple CSS trick to create an image's canvas cropping effect on hover? For example, similar to this: Thanks in advance! ...

PHP Ajax Image Uploading and Storage

Is there a way to effortlessly upload an image and save it in the uploads folder without any page refresh? Not only that, but can we also have the uploaded image displayed on the screen within a designated div section? Unfortunately, I seem to encounter a ...

Is there a React equivalent to window.location.replace()?

For example, here is the code I use for my login button: var rJson = JSON.parse(request.responseText); if (rJson.success) { console.log("login success"); window.location.replace(redirectLink); } While it wor ...

Center-align the text in mui's textfield

What I'm looking for is this: https://i.stack.imgur.com/ny3cy.png Here's what I ended up with: https://i.stack.imgur.com/vh7Lw.png I attempted to apply the style to my input props, but unfortunately, it didn't work. Any suggestions? Than ...

The button works properly in JSFiddle, however, it is not able to clear the ordered list in the

DEMO Creating a script that captures mouse click coordinates and appends them to a list. The functionality works, except for an issue with the clear button not working properly. After making corrections in jsfiddle, the script functions correctly. Howeve ...

NodeJS JSONStream causing memory exhaustion issue

I've encountered an issue while trying to stream a large JSON file (94mb in size) from an HTTP request to a local file using the JSONStream library in NodeJS. Despite setting a memory flag of 256mb with node --max-old-space-size=256 .\main.js, th ...