Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change devDependency to dependency #1941

Closed
joshribakoff-sm opened this issue Mar 1, 2022 · 39 comments
Closed

Change devDependency to dependency #1941

joshribakoff-sm opened this issue Mar 1, 2022 · 39 comments

Comments

@joshribakoff-sm
Copy link

joshribakoff-sm commented Mar 1, 2022

You have d3-scale as a devDependency for nivo legends https://github.com/plouc/nivo/blob/master/packages/legends/package.json#L27

When we try to run your basic "hello world" examples we got:

Cannot find module 'd3-scale' from '../../node_modules/@nivo/legends/dist/nivo-legends.cjs.js'

    Require stack:
      /my-project/node_modules/@nivo/legends/dist/nivo-legends.cjs.js
      /my-project/node_modules/@nivo/line/dist/nivo-line.cjs.js

This should be moved to dependency or added as a peerDependency (preferably the former), otherwise it requires the user of Nivo to debug this. Naively one may try to install d3-scale in their package.json which will cause even more issues since the latest major version of said package is relying on experimental node features which will throw nonsensical errors taking the user further down the rabbit hole.

I believe this one small fix will greatly improve the DX for this library.

The code you publish in your dist for legends does a require("d3-scale") so this is not a devDependency.

@lillijo
Copy link

lillijo commented Mar 9, 2022

I guess this issue is related?
I am getting this error trying to use @nivo/line
( I already have d3-scale installed for something else)

Error: require() of ES Module /project/node_modules/d3-scale/src/index.js from 
/project/node_modules/@nivo/legends/dist/nivo-legends.cjs.js not supported.
Instead change the require of index.js in /project/node_modules/@nivo/legends/dist/nivo-legends.cjs.js 
to a dynamic import() which is available in all CommonJS modules.

@joshribakoff-sm
Copy link
Author

@lillijo Try to downgrade the major version of d3-scale, you're running into the same issue we hit.

@davidcalhoun
Copy link
Contributor

davidcalhoun commented Mar 14, 2022

I added more details to #1951, but in short in 0.79 @nivo/legends is now using d3-scale and @nivo/colors in compute.ts. Both dependencies were added to legend's devDependencies, but since this code appears to run in prod it should be added to dependencies instead.

If using Yarn 2/3 berry you can add this temporary workaround to .yarnrc.yml which clears up the error (don't forget to rerun yarn install after adding it):

# .yarnrc.yml

...

packageExtensions:
    '@nivo/legends@*':
        dependencies:
            'd3-scale': '*'
            '@nivo/colors': '*'
...

Another successful workaround is to downgrade Nivo to 0.78

@davidcalhoun
Copy link
Contributor

davidcalhoun commented Mar 14, 2022

I think there's a slightly different issue mentioned by @joshribakoff-sm I'm seeing this issue with d3-scale v4 when trying to build the app with Next.js:

../../.yarn/__virtual__/@nivo-legends-virtual-c3468b9dca/0/cache/@nivo-legends-npm-0.79.1-dd1c63aa09-1f4bb8da28.zip/node_modules/@nivo/legends/dist/nivo-legends.cjs.js
Module not found: ESM packages (d3-scale) need to be imported. Use 'import' to reference the package instead. https://nextjs.org/docs/messages/import-esm-externals

EDIT: switching to Next.js loose mode as suggested by the link in the error seems to fix the issue!

@stale
Copy link

stale bot commented Jun 13, 2022

This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment!

@stale stale bot added the stale label Jun 13, 2022
@davidcalhoun
Copy link
Contributor

Bump

@netzwerg
Copy link
Contributor

If using Yarn 2/3 berry you can add this temporary workaround to .yarnrc.yml which clears up the error (don't forget to rerun yarn install after adding it):

# .yarnrc.yml

...

packageExtensions:
    '@nivo/legends@*':
        dependencies:
            'd3-scale': '*'
            '@nivo/colors': '*'
...

This only worked for me if declared as peerDependencies (possibly because I had both of them as dependencies in my package.json already):

...
 packageExtensions:
     '@nivo/legends@*':
         peerDependencies:
             'd3-scale': '*'
             '@nivo/colors': '*'
 ...

phgn0 added a commit to lindylearn/unclutter that referenced this issue Dec 11, 2022
@stale
Copy link

stale bot commented Feb 2, 2023

This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment!

@stale stale bot added the stale label Feb 2, 2023
@joshribakoff-sm
Copy link
Author

Not stale.

@stale stale bot removed the stale label Feb 2, 2023
@eholt201
Copy link

finding nivo unusable with create-t3-app due to this issue, any suggestions?

@plouc
Copy link
Owner

plouc commented Apr 28, 2023

I'm trying to address this issue in #2313

@IshfaqAhmedProg
Copy link

Has this issue been fixed? I'm still getting this error while trying to use @nivo/funnel

Error: require() of ES Module node_modules\d3-color\src\index.js from node_modules@nivo\colors\dist\nivo-colors.cjs.js not supported.Instead change the require of index.js in node_modules@nivo\colors\dist\nivo-colors.cjs.js to a dynamic import() which is available in all CommonJS modules.

It gets fixed if I change my next js config to

const nextConfig = { reactStrictMode: true, transpilePackages: ["@nivo"], experimental: { esmExternals: "loose", } }

But this hardly seems like a solution, and I'm kind of stuck using nivo, as I found only nivo to provide really good React-friendly docs and good-looking default styling. I've used react-chart-js-2 and material UI, as well on the project could those be causing conflicts?

@plouc
Copy link
Owner

plouc commented May 12, 2023

@IshfaqAhmedProg why do you think it's not a solution? This is what next recommends in such case.

I'm kind of stuck using nivo, as I found only nivo to provide really good React-friendly docs and good-looking default styling.

It seems like you're "stuck" for good reasons at least :)

Also the issue you're reporting is different from this one, it's more about #2310.

@plouc
Copy link
Owner

plouc commented May 12, 2023

The issue has been solved in 0.82.0 via #2313.

@plouc plouc closed this as completed May 12, 2023
@julienmunar
Copy link

@plouc hello, so what do we have to do to correct the issue ?

@plouc
Copy link
Owner

plouc commented May 16, 2023

@julienmunar hello, to install the latest version, but please note that you might run into import issues depending on your setup due to esm only d3 packages (#2310).

@mt-hagen
Copy link

Hi @plouc - I am still experiencing this issue in 0.83.0, is this a common issue?

@Joeghanoe
Copy link

Experiencing this issue in 0.83.0 aswell here, how can we prevent this from happening?

@KupriyanovNikita
Copy link

Also bumped this issue in 0.83.0

@plouc
Copy link
Owner

plouc commented Jun 15, 2023

@mt-hagen, @Joeghanoe, @KupriyanovNikita, could you please provide more details? I'm a bit confused that it still happens as there's no dev dependencies anymore: https://github.com/plouc/nivo/blob/v0.83.0/packages/legends/package.json.

@lucaslosi
Copy link

i got a similar error building my nextjs project. Heres the trace if it helps:

info  - Collecting page data ...Error [ERR_REQUIRE_ESM]: require() of ES Module [***]\node_modules\d3-color\src\index.js from [***]\node_modules\@nivo\colors\dist\nivo-colors.cjs.js not supported.

importing these as dependencies:

        "@nivo/bar": "^0.83.0",
        "@nivo/core": "^0.83.0",
        "@nivo/line": "^0.83.0",
        "@nivo/pie": "^0.83.0",

@plouc
Copy link
Owner

plouc commented Jun 26, 2023

There are 2 different issues, which can be confusing I guess, dependencies weren't properly defined, it's especially an issue when using pnpm for example (this issue), this has been fixed, the other issue is: #2310

@TejasFresh
Copy link

I still get the same error in 0.83 when I use @nivo/line

@coderdix24
Copy link

same issue with @nivo/radial-bar

@coderdix24
Copy link

@IshfaqAhmedProg why do you think it's not a solution? This is what next recommends in such case.

I'm kind of stuck using nivo, as I found only nivo to provide really good React-friendly docs and good-looking default styling.

It seems like you're "stuck" for good reasons at least :)

Also the issue you're reporting is different from this one, it's more about #2310.

this didn't work for me, getting error
/node_modules/@nivo/colors/dist/nivo-colors.cjs.js not supported.

Instead change the require of index.js in /srv/v2/browser/node_modules/@nivo/colors/dist/nivo-colors.cjs.js to a dynamic import() which is available in all CommonJS modules.

@IshfaqAhmedProg
Copy link

IshfaqAhmedProg commented Jul 7, 2023

@IshfaqAhmedProg why do you think it's not a solution? This is what next recommends in such case.

I'm kind of stuck using nivo, as I found only nivo to provide really good React-friendly docs and good-looking default styling.

It seems like you're "stuck" for good reasons at least :)
Also the issue you're reporting is different from this one, it's more about #2310.

this didn't work for me, getting error /node_modules/@nivo/colors/dist/nivo-colors.cjs.js not supported.

Instead change the require of index.js in /srv/v2/browser/node_modules/@nivo/colors/dist/nivo-colors.cjs.js to a dynamic import() which is available in all CommonJS modules.

Try updating using npm i @nivo/[email protected] @nivo/<modname>@0.83.0 replace modname with the module you're using like "funnel", "bar" etc. and then try changing the next js config. Thats what worked for me, you will still get the high risk vulnerabilities found when you run "npm audit". Without this package i get 5 moderate vulnerabilities, with the package i get 21 high risk and 5 moderate!

@coderdix24
Copy link

Try updating using npm i @nivo/[email protected] @nivo/<modname>@0.83.0 replace modname with the module you're using like "funnel", "bar" etc. and then try changing the next js config. Thats what worked for me, you will still get the high risk vulnerabilities found when you run "npm audit". Without this package i get 5 moderate vulnerabilities, with the package i get 21 high risk and 5 moderate!

I appreciate your reply!
I had it at that version and still getting the same error - I'm not sure what to do, really needed that radial bar chart

@IshfaqAhmedProg
Copy link

Try updating using npm i @nivo/[email protected] @nivo/<modname>@0.83.0 replace modname with the module you're using like "funnel", "bar" etc. and then try changing the next js config. Thats what worked for me, you will still get the high risk vulnerabilities found when you run "npm audit". Without this package i get 5 moderate vulnerabilities, with the package i get 21 high risk and 5 moderate!

I appreciate your reply!
I had it at that version and still getting the same error - I'm not sure what to do, really needed that radial bar chart

I forgot to say even i had it at 0.83.0 when i first installed the package, then after encountering the error i ran npm audit fix --force which downgraded the package version to, from what i remember, 0.81.0, then i manually updated it using the command stated above, that let me use it fine without any runtime error! Also if you're using next js in the #2310 issue, some people solved it using dynamic import although that didnt work for me as i needed it to be SSR!

@bruno-gurgel
Copy link

Still having this problem on 0.83.0. Any solution by now?

@mmaker
Copy link

mmaker commented Jul 26, 2023

same here

1 similar comment
@codesjedi
Copy link

same here

@willemmulder
Copy link

@IshfaqAhmedProg why do you think it's not a solution? This is what next recommends in such case.

I'm kind of stuck using nivo, as I found only nivo to provide really good React-friendly docs and good-looking default styling.

It seems like you're "stuck" for good reasons at least :)
Also the issue you're reporting is different from this one, it's more about #2310.

this didn't work for me, getting error /node_modules/@nivo/colors/dist/nivo-colors.cjs.js not supported.

Instead change the require of index.js in /srv/v2/browser/node_modules/@nivo/colors/dist/nivo-colors.cjs.js to a dynamic import() which is available in all CommonJS modules.

@plouc Could you implement this fix? Thanks!

@willemmulder
Copy link

For an ugly workaround in Next.js you could add the following to your next.config.js

transpilePackages: ["@nivo"], 
experimental: { esmExternals: "loose" }

@pixelmultiplo
Copy link

So it's unusable in next.js?

@javierfuentesm
Copy link

im having this issue with remix too any dieas?

@DaveCole
Copy link

DaveCole commented Sep 13, 2023

Same issue with @nivo/network - using the loose mode in next.config.js only seems to fix the issue every 2-3 reloads (this is using Next v12). Can confirm that rolling back to 0.79 fixes the issue @plouc - my instincts tell me this has something to do with server-side rendering maybe?

edit: rolling back to 0.79 fixed Network but broke Bullet. See my workaround below.

@DaveCole
Copy link

DaveCole commented Sep 14, 2023

For what it's worth, a workaround is to wrap a container component around the offending Nivo chart (I have trouble with Network and Bullet at the moment, but I suspect it's all the charts), save it as it's own file so that's the file that imports directly from @nivo, and then use Next.js's dynamic import with ssr: false to import it during a client-side render:

import dynamic from 'next/dynamic';

...

const MyResponsiveNetwork = dynamic(() => import('./MyResponsiveNetwork'), { ssr: false } );

@Jon-Robb
Copy link

Jon-Robb commented May 1, 2024

For what it's worth, a workaround is to wrap a container component around the offending Nivo chart (I have trouble with Network and Bullet at the moment, but I suspect it's all the charts), save it as it's own file so that's the file that imports directly from @nivo, and then use Next.js's dynamic import with ssr: false to import it during a client-side render:

import dynamic from 'next/dynamic';

...

const MyResponsiveNetwork = dynamic(() => import('./MyResponsiveNetwork'), { ssr: false } );

This fixed the issue for me thanks

@camiloux
Copy link

TL;DR: The error occurs on the server side; try client-side loading instead.

I encountered the same issue when using the Nivo library with Astro and React:

"require() of ES Module .../node_modules/d3-interpolate/src/index.js from .../node_modules/@nivo/core/dist/nivo-core.cjs.js not supported. Instead, change the require of index.js in .../node_modules/@nivo/core/dist/nivo-core.cjs.js to a dynamic import() which is available in all CommonJS modules."

This issue arises when trying to use nivo components on the server side. I resolved it by configuring my component to load client-side only. In Astro, you can do this by setting client:only="react". After making this change, everything worked smoothly, and my chart rendered as expected. For reference, I'm using Nivo version 0.87.0.

For developers facing similar issues with Next.js, you might need to set ssr: false to ensure the components load on the client side only.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests