sim51 / react-sigma

Sigma React component
https://sim51.github.io/react-sigma/
MIT License
172 stars 27 forks source link

Cannot find module '*/node_modules/graphology-layout-forceatlas2/worker' #67

Open totase opened 4 months ago

totase commented 4 months ago

I use react-sigma with vite, but when I run tests I get the following error in the console and the tests fail:

Error: Cannot find module '*/node_modules/graphology-layout-forceatlas2/worker' imported from */node_modules/@react-sigma/layout-forceatlas2/lib/react-sigma_layout-forceatlas2.esm.min.js
Did you mean to import graphology-layout-forceatlas2/worker.js?

Note that the application runs as expected, and I have no issue building the project. See list of dependencies below:

    "@react-sigma/core": "^4.0.2",
    "@react-sigma/layout-forceatlas2": "^4.0.2",
    "@sigma/edge-curve": "^3.0.0-beta.7",
    "classnames": "^2.5.1",
    "graphology": "^0.25.4",
    "graphology-types": "^0.24.7",
    "react": "^18.3.0",
    "sigma": "^3.0.0-beta.18",

    "vite": "^5.0.8",
    "vitest": "^1.2.1"

Operating System: Ubuntu 20.04.6 LTS

If I navigate to the module package it complains about (*/node_modules/@react-sigma/layout-forceatlas2/lib/react-sigma_layout-forceatlas2.esm.min.js) and manually change the import from import e from"graphology-layout-forceatlas2/worker"; to import e from"graphology-layout-forceatlas2/worker.js";, the tests run as expected. Is there any way to fix this within the package?

sim51 commented 4 months ago

I'm not sure it's an issue with the package, due to the fact that you need to add the extension. What version of graphology-layout-forceatlas2 do you use ? Can you share your vite config file ?

MylesWritesCode commented 2 months ago

Unsure of vite's config, but I'm using webpack and I was able to get around this by using an alias e.g.

const config = {
  resolve: {
      alias: {
        'graphology-layout-forceatlas2/worker': 'graphology-layout-forceatlas2/worker.js', // added this here
      },
    },
  // ...rest of config
}