nivo icon indicating copy to clipboard operation
nivo copied to clipboard

Change devDependency to dependency

Open joshribakoff-sm opened this issue 2 years ago • 7 comments

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.

joshribakoff-sm avatar Mar 01 '22 21:03 joshribakoff-sm

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.

lillijo avatar Mar 09 '22 17:03 lillijo

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

joshribakoff-sm avatar Mar 09 '22 19:03 joshribakoff-sm

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 avatar Mar 14 '22 19:03 davidcalhoun

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!

davidcalhoun avatar Mar 14 '22 19:03 davidcalhoun

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[bot] avatar Jun 13 '22 01:06 stale[bot]

Bump

davidcalhoun avatar Jun 13 '22 14:06 davidcalhoun

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': '*'
 ...

netzwerg avatar Aug 15 '22 12:08 netzwerg

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[bot] avatar Feb 02 '23 02:02 stale[bot]

Not stale.

joshribakoff-sm avatar Feb 02 '23 18:02 joshribakoff-sm

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

eholt201 avatar Mar 24 '23 14:03 eholt201

I'm trying to address this issue in https://github.com/plouc/nivo/pull/2313

plouc avatar Apr 28 '23 22:04 plouc

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?

IshfaqAhmedProg avatar May 12 '23 19:05 IshfaqAhmedProg

@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 https://github.com/plouc/nivo/issues/2310.

plouc avatar May 12 '23 19:05 plouc

The issue has been solved in 0.82.0 via #2313.

plouc avatar May 12 '23 20:05 plouc

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

julienmunar avatar May 16 '23 09:05 julienmunar

@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).

plouc avatar May 16 '23 09:05 plouc

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

mt-hagen avatar May 25 '23 09:05 mt-hagen

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

Joeghanoe avatar May 29 '23 16:05 Joeghanoe

Also bumped this issue in 0.83.0

KupriyanovNikita avatar Jun 15 '23 16:06 KupriyanovNikita

@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.

plouc avatar Jun 15 '23 17:06 plouc

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",

lucaslosi avatar Jun 19 '23 18:06 lucaslosi

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: https://github.com/plouc/nivo/issues/2310

plouc avatar Jun 26 '23 02:06 plouc

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

TejasFresh avatar Jul 06 '23 11:07 TejasFresh

same issue with @nivo/radial-bar

coderdix24 avatar Jul 07 '23 20:07 coderdix24

@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.

coderdix24 avatar Jul 07 '23 20:07 coderdix24

@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!

IshfaqAhmedProg avatar Jul 07 '23 22:07 IshfaqAhmedProg

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

coderdix24 avatar Jul 07 '23 23:07 coderdix24

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!

IshfaqAhmedProg avatar Jul 07 '23 23:07 IshfaqAhmedProg

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

bruno-gurgel avatar Jul 20 '23 16:07 bruno-gurgel

same here

mmaker avatar Jul 26 '23 12:07 mmaker