Common JS library import in ES Module
Akbar Ali

Akbar Ali @pulimoodan

About: Web dev and designer.

Location:
Kerala, India
Joined:
Jan 15, 2022

Common JS library import in ES Module

Publish Date: Jul 21
1 0

Spent a lot of time debugging this.

I was using react color library from NPM in a project and my project was in ES module scope.

Problem

import reactColor from "react-color";
Enter fullscreen mode Exit fullscreen mode
TypeError: Cannot read properties of undefined (reading 'displayName')
Enter fullscreen mode Exit fullscreen mode

Fix

import * as reactColor from "react-color";
Enter fullscreen mode Exit fullscreen mode
const { SketchPicker } = reactColor;
Enter fullscreen mode Exit fullscreen mode

Comments 0 total

    Add comment