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

Doesn't work with Vitejs #594

Open
simoneb opened this issue Aug 20, 2023 · 10 comments · May be fixed by #604
Open

Doesn't work with Vitejs #594

simoneb opened this issue Aug 20, 2023 · 10 comments · May be fixed by #604

Comments

@simoneb
Copy link

simoneb commented Aug 20, 2023

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.

@kosamtech
Copy link

Yeah likewise I encountered the same problem 🤔

@kosamtech
Copy link

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

@simoneb
Copy link
Author

simoneb commented Aug 24, 2023

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
Copy link

same here

@je4ngomes
Copy link

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
Copy link

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.

@ekynoxe ekynoxe linked a pull request Oct 5, 2023 that will close this issue
@ekynoxe
Copy link

ekynoxe commented Oct 5, 2023

I've created a draft PR (#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
Copy link

rchavp commented Dec 18, 2023

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
Copy link

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!

@HubertTGit
Copy link

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

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

Successfully merging a pull request may close this issue.

9 participants