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.81k stars 209 forks source link

Bug: Failed to resolve entry for package "danfojs" #545

Open devMagno opened 1 year ago

devMagno commented 1 year ago

Describe the bug I've installed danfojs@^1.1.2 in my React project using Vite and I'm getting the following error:

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

I really don't know what to do, I tried googling the error and found nothing. At first I thought it was a bug involving Vite, but then I tried using CRA and the bug still happens.

Screenshots image

steveoni commented 1 year ago

@devMagno you can check how it’s use for CRA here https://github.com/javascriptdata/Data-aRT

devMagno commented 1 year ago

Thanks! It worked for me, but I would really like to use Danfo for Vite :(

ttarabbia commented 1 year ago

Same here - rolled back to 1.1.1 - unfortunately that means I can't use parsing options in readExcel.... Haven't found a way to fix - tried the absolute path, tried changing entry point, like https://github.com/javascriptdata/danfojs/pull/516

Unfortunately still breaks in Vite.

ttarabbia commented 1 year ago

Similar to issue #527

ttarabbia commented 1 year ago

Also take a look at #514

S-L-Moore commented 1 year ago

Found a workaround on this thread: Discussions 525

fahminlb33 commented 1 year ago

Aside from the workaround on the https://github.com/javascriptdata/danfojs/discussions/525, I tried the https://github.com/javascriptdata/danfojs/pull/447 PR locally and it worked on Vite + React.

Repro steps:

  1. Clone the danfo repo
  2. yarn and yarn build
  3. You'll see two different build in the src/danfojs-browser/lib, the esbuild version (bundle.esm.js) and webpack version (bundle-esm.js)
  4. If you're using Vite, the esbuild is the one you want.

How I used the esbuild bundle version in my app:

import { Button, Text } from '@mantine/core';

import * as dfd from '../../../danfo2/bundle.esm.js'; // place the file somewhere, in this case in my src dir

export default function Create() {
  async function load_process_data() {
    let df = await dfd.readCSV('/titanic.csv');
    console.log(df.head().print());
    console.log(df.ctypes.print());

    const title = df['Name'].apply((x: string) => { return x.split(".")[0] }).values

    df.addColumn("Name", title, {inplace: true});
    console.log(df.head().print());
  }

  return (
    <div>
      <Text>Create</Text>
      <Button onClick={load_process_data}>Load Data</Button>
    </div>
  );
}

So based on these findings, we have to options.

  1. The webpack version, if you want to include danfo from <script> tag
  2. The esbuild version, if you want to import danfo from Vite

Based on my node_modules the bundle installed using npm install danfojs is the webpack version and the esbuild version are not even included in the package. Also, the module field in the package.json in the npm package is pointing to a wrong file, it should be lib/bundle.js not lib/bundle-esm.js