danfojs icon indicating copy to clipboard operation
danfojs copied to clipboard

Doesn't work with Vitejs

Open simoneb opened this issue 1 year ago • 10 comments

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.

simoneb avatar Aug 20 '23 18:08 simoneb

Yeah likewise I encountered the same problem :thinking:

kosamtech avatar Aug 23 '23 19:08 kosamtech

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

kosamtech avatar Aug 24 '23 11:08 kosamtech

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.

simoneb avatar Aug 24 '23 13:08 simoneb

same here

ivan-sparq avatar Sep 03 '23 19:09 ivan-sparq

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

je4ngomes avatar Sep 12 '23 16:09 je4ngomes

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/[email protected]/lib/bundle.min.js" /> then you can use dfd globally.

michael1997 avatar Oct 03 '23 04:10 michael1997

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

ekynoxe avatar Oct 05 '23 12:10 ekynoxe

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.

rchavp avatar Dec 18 '23 09:12 rchavp

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:

  • Clone their code: https://github.com/javascriptdata/danfojs.git
  • In package.json of my project I added the dependency: "danfojs": "file:///C:/GitRepo/danfojs/src/danfojs-browser"
  • Change directory to danfojs/src/danfojs-browser
  • Edit package.json line 7: "module": "lib/bundle.esm.js"
  • Run yarn build:esm-bundle
  • Done!

intercodesys avatar Dec 19 '23 09:12 intercodesys

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

HubertTGit avatar Jun 24 '24 11:06 HubertTGit