Git Product home page Git Product logo

Comments (4)

bmaranville avatar bmaranville commented on May 16, 2024

This seems to be an error that only occurs with testing, and it seems like this is an error specifically with jest - it is expecting the imports to be CJS unless you make some special notation. (Apps work just fine).

For the moment, you can indicate to jest that the jsfive import is an ES module, by

-    "test": "react-scripts test",
+    "test": "react-scripts test --transformIgnorePatterns \"node_modules/(?!(jsfive))/\"",

Longer term, I am updating the package.json (see 64e0927) so that the imports are identifiable as CJS and ESM. This will affect the next release.

from jsfive.

hubbardp avatar hubbardp commented on May 16, 2024

Thanks. That solution works for the specific problem with Jest, so I will close this issue.

I am still having problems with versions after 0.3.5, though. Specifically, I have an NPM module, B, that imports jsfive, and then an application, A, created with create-react-app that imports B (using npm link for development). I can start A but when it calls code from B it fails:

TypeError: hdf5.File is not a constructor
B.js:112 stack: TypeError: hdf5.File is not a constructor
    at FileReader.reader.onload (https://localhost:3000/static/js/main.chunk.js:230:34)

I don't need any fancy HDF5 capabilities, so for now, at least, my solution is to just continue using 0.3.5, but I am hoping the problem is solved in the next release, as you mentioned.

from jsfive.

bmaranville avatar bmaranville commented on May 16, 2024

I am having trouble reproducing the issue you describe - I created a dummy package jsfive-test with an installed [email protected] and this index.js:

import * as hdf5 from 'jsfive';

const DEFAULT_URL = "https://ncnr.nist.gov/pub/ncnrdata/vsans/202009/27864/data/sans66167.nxs.ngv";

export async function load_and_show_keys(file_url = DEFAULT_URL) {
  const result = await fetch(file_url);
  const ab = await result.arrayBuffer();
  const f = new hdf5.File(ab, "file");
  const keys = f.keys;
  console.log(keys);
  return keys;
}

And then I did npx create-react-app in a separate folder, and npm link ../../jsfive-test, and added these lines to the header of src/App.js, and it is able to run and outputs the expected keys for the loaded file when I run npm start

import logo from './logo.svg';
import './App.css';
import  {load_and_show_keys} from 'jsfive-test';

load_and_show_keys();
...

Are you building the intermediate library B with webpack or something like that? I would like to reproduce the problem so I can verify that the new package.json layout would address it.

from jsfive.

bmaranville avatar bmaranville commented on May 16, 2024

I think in 0.3.6 to 0.3.9 I wasn't creating a CommonJS module, and I think that is what is getting pulled into CRA for some reason (this seems to happen in webpack).

I have added a CommonJS module back into version 0.3.10

from jsfive.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.