Yoctol / react-d3-cloud

A word cloud react component built with d3-cloud.
https://yoctol.github.io/react-d3-cloud
MIT License
138 stars 47 forks source link

webpack unable to resolve reference to react-d3-cloud since updating from 0.11.0 to 1.0.3 #138

Closed shaggyfrog closed 2 years ago

shaggyfrog commented 2 years ago

I am working on a project using an older version of react-d3-cloud, 0.11.0, before it was converted to Typescript.

When I update the dependency to 1.0.3, webpack fails to build.

The library is imported in a normal way: import WordCloud from 'react-d3-cloud'; However, webpack is unable to resolve the reference.

Looking at package.json, I believe the main field is defined correctly:

https://github.com/Yoctol/react-d3-cloud/blob/02cd7f477d3aae8292e4d86e58b8888135ab1394/package.json#L12

The exports field was added in 1.0.1, and it is defined as:

https://github.com/Yoctol/react-d3-cloud/blob/02cd7f477d3aae8292e4d86e58b8888135ab1394/package.json#L93-L94

The webpack documentation says that the exports field overrides the value of main.

I believe the paths in the values for these two fields is incorrect. Looking at the actual package inside node_modules after installing, I believe these field values should be

    "import": "./lib/esm/index.js", 
    "require": "./lib/index.js" 

If I use 1.0.0 (the first version with Typescript), webpack builds correctly. If I use 1.0.1, when the exports field was added, webpack fails.

Is this correct, or am I installing/using react-d3-cloud incorrectly?

chentsulin commented 2 years ago

Definitely it was a mistake. Thanks for pointing out!

chentsulin commented 2 years ago

@shaggyfrog I just released a new version here: https://github.com/Yoctol/react-d3-cloud/releases/tag/v1.0.4 See if it works in your case.

shaggyfrog commented 2 years ago

@chentsulin It works, thanks!