yanivam / react-svg-worldmap

A simple, compact and free React SVG world map.
MIT License
119 stars 43 forks source link

[BUG] problem with build next js app #135

Closed AlexeyGlaznev closed 1 year ago

AlexeyGlaznev commented 2 years ago

Each time when I run 'next build' command I get this error: Collecting page data ..Error [ERR_REQUIRE_ESM]: require() of ES Module node_modules/d3-geo/src/index.js from node_modules/react-svg-worldmap/dist/index.js not supported. Instead change the require of node_modules/d3-geo/src/index.js in node_modules/react-svg-worldmap/dist/index.js to a dynamic import() which is available in all CommonJS modules. This error exists in any Next js application, without any other dependencies except of default next js dependencies

Steps to reproduce the behavior:

  1. npx create-next-app@latest
  2. npm i react-svg-worldmap
  3. In any file write this: import WorldMap from 'react-svg-worldmap' console.log(WorldMap)
  4. npm run build

Expected behavior Building without problems

Desktop (please complete the following information):

The strange thing is that 'npm run dev' doesn't give any errors and you can use the package without any problems in the dev mode.

nathanhfoster commented 2 years ago

Each time when I run 'next build' command I get this error: Collecting page data ..Error [ERR_REQUIRE_ESM]: require() of ES Module node_modules/d3-geo/src/index.js from node_modules/react-svg-worldmap/dist/index.js not supported. Instead change the require of node_modules/d3-geo/src/index.js in node_modules/react-svg-worldmap/dist/index.js to a dynamic import() which is available in all CommonJS modules. This error exists in any Next js application, without any other dependencies except of default next js dependencies

Steps to reproduce the behavior:

  1. npx create-next-app@latest
  2. npm i react-svg-worldmap
  3. In any file write this: import WorldMap from 'react-svg-worldmap' console.log(WorldMap)
  4. npm run build

Expected behavior Building without problems

Desktop (please complete the following information):

  • OS: MacOS 12.1
  • Browser Chrome

The strange thing is that 'npm run dev' doesn't give any errors and you can use the package without any problems in the dev mode.

I am experiencing the same problem.

dbaileydev commented 1 year ago

I am experiencing the same issue on my next js app. Package won't build. Instead change the require of .../node_modules/d3-geo/src/index.js in .../node_modules/react-svg-worldmap/dist/index.js to a dynamic import() which is available in all CommonJS modules.

razzeee commented 1 year ago

If you need an OSS app to repro this with, feel free to use https://github.com/flathub/website/pull/550

Josh-Cena commented 1 year ago

Sorry, I have very limited availability to debug this. My hypothesis is that Next.js' Webpack config doesn't transpile modules in node_modules by default, and we now emit ESM format. Is it possible to modify the Next.js webpack config?

yanivam commented 1 year ago

Sorry everyone, I have been away doing my Masters and working full time. I am going to get back to this starting tomorrow. Thanks for your patience. -Yams

yanivam commented 1 year ago

Hey @razzeee , @dbaileydev , @nathanhfoster , and @AlexeyGlaznev . The above error should be resolved in the latest version of the map on npm that I just posted. Can any of y'all check and close this issue? I was able to create a next.js app with the steps above with no compile issues. The issue was with the d3-geo and esm. Thanks, Yams

razzeee commented 1 year ago

Seems to build fine now https://github.com/flathub/website/pull/1313/files

yanivam commented 1 year ago

In that case I will close this issue, thanks for the quick reply @razzeee!

yanivam commented 1 year ago

Fixed by #144