javascriptdata / danfojs

Danfo.js is an open source, JavaScript library providing high performance, intuitive, and easy to use data structures for manipulating and processing structured data.
https://danfo.jsdata.org/
MIT License
4.72k stars 210 forks source link

Doesn't work with Vitejs #594

Open simoneb opened 10 months ago

simoneb commented 10 months ago

Describe the bug

Danfojs cannot be loaded in a Vitejs project.

To Reproduce Steps to reproduce the behavior:

  1. Create a new Vitejs project
  2. Install danfojs as a dependency
  3. Import it in any module of the application with import * as dfd from 'danfojs'
  4. See the error below:

[plugin:vite:import-analysis] Failed to resolve entry for package "danfojs". The package may have incorrect main/module/exports specified in its package.json.

Expected behavior

The import works and you can use danfojs in your Vitejs app

Repro

You can see a repro in CodeSandbox here. Creating a new Vitejs application locally leads to the same issue (meaning that it's not an issue with CodeSandbox), and the issue happens regardless of whether you use TypeScript or JavaScript.

kkthecompguy commented 10 months ago

Yeah likewise I encountered the same problem :thinking:

kkthecompguy commented 10 months ago

Hey @simoneb is there any work around you did about this to work?

simoneb commented 10 months ago

I fiddled around with the installed package's package.json file but it wasn't by any means a robust solution. The fix should be fairly simple though, it's just a matter of getting the exports right in the package file.

ivan-sparq commented 10 months ago

same here

je4ngomes commented 9 months ago

While this is not fixed, here is a temporary solution at least worked for me, btw i'm using yarn.

add this to your package.json file:

"resolutions": { "mathjs": "11.11.0" },

michael1997 commented 9 months ago

My less than ideal workaround to get it going before this is fixed is just loading via script tags <script src="https://cdn.jsdelivr.net/npm/danfojs@1.1.2/lib/bundle.min.js" /> then you can use dfd globally.

ekynoxe commented 8 months ago

I've created a draft PR (https://github.com/javascriptdata/danfojs/pull/604) with an implementation that works locally, but I'm not too happy with.

I'm new to package exports, so it's all a little blurry, hence why I'm keeping this one as a draft, but hopefully that's a start to fix the issues and could do with some help to finish it off.

Both for a new vite app and a new CRA app, I've linked the package locally with npm link danfojs, then used the following code in the root file:

import * as dfd from 'danfojs'
const s = new dfd.Series([1, 3, 5, undefined, 6, 8])
s.print()

Both apps run fine without runtime errors and display the series in the console.

Screenshot 2023-10-05 at 12 55 36 Screenshot 2023-10-05 at 12 55 18

However, types don't work, and I get the following error in CRA terminal output:

WARNING in ../danfojs/src/danfojs-browser/lib/bundle.esm.js 9:47-54
Critical dependency: require function is used in a way in which dependencies cannot be statically extracted

WARNING in ../danfojs/src/danfojs-browser/lib/bundle.esm.js 12:44-51
Critical dependency: require function is used in a way in which dependencies cannot be statically extracted
rchavp commented 6 months ago

Has anyone figured out how to fix this issue? I was really looking forward to using this library in our production pipeline, but I can't remove Vite unfortunately and local hacks/fixes are a no go either.

intercodesys commented 6 months ago

I managed to get it work in ViteJS. I found out that the main problem is that they pointed out "module": "lib/bundle-esm.js" when it should actually be "module": "lib/bundle.esm.js". (the path is incorrect).

To get it working:

HubertTGit commented 1 week ago

This hack works for me, instead of import * as dfd from "danfojs" do import * as dfd from "danfojs/dist/danfojs-browser/src"