danfojs
danfojs copied to clipboard
Bug: Failed to resolve entry for package "danfojs"
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
@devMagno you can check how it’s use for CRA here https://github.com/javascriptdata/Data-aRT
Thanks! It worked for me, but I would really like to use Danfo for Vite :(
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.
Similar to issue #527
Also take a look at #514
Found a workaround on this thread: Discussions 525
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:
- Clone the danfo repo
-
yarn
andyarn build
- You'll see two different build in the
src/danfojs-browser/lib
, the esbuild version (bundle.esm.js) and webpack version (bundle-esm.js) - 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.
- The webpack version, if you want to include danfo from
<script>
tag - 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