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

Dist folder files is not covered in package.json exports field #3239

Closed
7 tasks
odeadglaz opened this issue Apr 18, 2024 · 10 comments
Closed
7 tasks

Dist folder files is not covered in package.json exports field #3239

odeadglaz opened this issue Apr 18, 2024 · 10 comments
Assignees
Labels
bug A bug in the code of Cytoscape.js

Comments

@odeadglaz
Copy link

odeadglaz commented Apr 18, 2024

Environment info

  • Cytoscape.js version : 3.29.0
  • Node.js & version : any Node version that supports exports field

Current (buggy) behaviour

In the current behaviour, this package was added an exports field to its package.json which doesn't cover all the dist folder consumble outputs.

Desired behaviour

I would be able to directly consume any dist file e.g

require('cytoscape/dist/cytoscape.umd')

Minimum steps to reproduce

Use the latest version and have this simple test file:

const test = require('cytoscape'); // works

console.log(test);

const testFail = require('cytoscape/dist/cytoscape.umd'); // Fails

console.log(testFail);
image

I would expect anything I can consume would be covered over the exports field 👍

For example the following condition would be sufficient ->

    "./dist/*": {
      "import": "./dist/*.js",
      "require": "./dist/*.js"
    }

For reviewers

Reviewers should ensure that the following tasks are carried out for incorporated issues:

  • Ensure that the reporter has included a reproducible demo. They can easily fork this JSBin demo: http://jsbin.com/fiqugiq
  • The issue has been associated with a corresponding milestone.
  • The commits have been incorporated into the corresponding branches. Bug-fix patches go on
    • master,
    • unstable, and
    • the previous feature release branch (e.g. 1.1.x if the current release is 1.2).
  • The issue has been labelled as a bug, if necessary.
@odeadglaz odeadglaz added the bug A bug in the code of Cytoscape.js label Apr 18, 2024
@cmfadib
Copy link

cmfadib commented Apr 18, 2024

can confirm this bug, got this error with 3.29.0 - ./node_modules/mermaid/dist/mindmap-definition-44684416.js:4:0-56 - Error: Module not found: Error: Package path ./dist/cytoscape.umd.js is not exported from package

ghostdogpr added a commit to zio/zio that referenced this issue Apr 18, 2024
Looks like there is an issue in this dependency: cytoscape/cytoscape.js#3239 so I am trying to force the previous version
ghostdogpr added a commit to zio/zio that referenced this issue Apr 18, 2024
* Fix build website CI

Looks like there is an issue in this dependency: cytoscape/cytoscape.js#3239 so I am trying to force the previous version

* Update package.json
@317brian
Copy link

317brian commented Apr 18, 2024

We're running into a similar issue trying to build/deploy Docusaurus (including the mermaid diagrams plugin which is what's bringing in cytoscape) on AWS Amplify:

Module not found: Error: Package path ./dist/cytoscape.umd.js is not exported from package /codebuild/output/.../node_modules/cytoscape (see exports field in /codebuild/output/.../node_modules/cytoscape/package.json)

@allala0
Copy link

allala0 commented Apr 20, 2024

I ran into similar error introduced by v3.29.0
Error:

(node:18962) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
/var/home/artur/Desktop/cytoscape-error/node_modules/cytoscape/dist/cytoscape.esm.js:31305
export { cytoscape as default };
^^^^^^

SyntaxError: Unexpected token 'export'
    at internalCompileFunction (node:internal/vm:73:18)
    at wrapSafe (node:internal/modules/cjs/loader:1178:20)
    at Module._compile (node:internal/modules/cjs/loader:1220:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
    at Module.load (node:internal/modules/cjs/loader:1119:32)
    at Module._load (node:internal/modules/cjs/loader:960:12)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:169:29)
    at ModuleJob.run (node:internal/modules/esm/module_job:194:25)

Node.js v18.17.1

Here is repo with minimum code to reproduce the error: https://github.com/allala0/cytoscape-error/

@mikekucera
Copy link
Contributor

3.29.1 has been released, please let me know if it resolves your issues

@jan-molak
Copy link
Contributor

jan-molak commented Apr 24, 2024

@mikekucera - thanks for looking into this. With 3.29.1, I'm still getting the following error:

Module not found: Error: Can't resolve 'cytoscape/dist/cytoscape.umd.js' 
 in '/path-to-project/node_modules/mermaid/dist'

Update 1: It looks like Mermaid's patching Cytoscape. Perhaps that's something that could be done on the Cytoscape side so that Mermaid can avoid patching? Or perhaps Mermaid should use Cytoscape differently? 🤔

@mikekucera
Copy link
Contributor

Hi @jan-molak
Thank you for the feedback. Max is currently not available to manage the cytoscape.js project like he normally does. I'm managing the release process in the meantime. I apologize, I have very little experience with javascript build systems. I don't know why Mermaid needs to patch cytoscape.js, but it looks like they are patching the exports. Perhaps the latest changes to the exports in 3.29.1 will obviate the need to do that?

@jan-molak
Copy link
Contributor

@mikekucera - thanks for getting back to me. No worries, JavaScript build systems are anything but intuitive :-)

I proposed a fix in #3241

I believe the issue is caused by Mermaid requiring Cytoscape using:

import cytoscape from "cytoscape/dist/cytoscape.umd.js";

But Cytoscape defines exports as:

    "./dist/*": {
      "import": "./dist/*.js",
      "require": "./dist/*.js"

and so:

import cytoscape from "cytoscape/dist/cytoscape.umd.js"

is translated to:

"cytoscape/dist/cytoscape.umd.js.js"

Another possible fix could be to drop .js from ./dist/* exports, like so:

    "./dist/*": {
-      "import": "./dist/*.js",
+      "import": "./dist/*",
-      "require": "./dist/*.js"
+      "require": "./dist/*",      

However, this alternative approach may or may not have a negative effect on other consumers of Cytoscape, so perhaps you'd like to review #3241 as a temporary solution, and the more general solution upon Max's return?

@silverwind
Copy link

silverwind commented Apr 25, 2024

Adding @sidharthv96 regarding those patches in mermaid, hopefully they can be removed after this is resolved.

mikekucera added a commit that referenced this issue Apr 25, 2024
fix(umd): exported cytoscape.umd, closes #3239
@mikekucera
Copy link
Contributor

3.29.2 has been released, please let me know if it resolves your issues

This issue was auto-closed by the commit in the PR. If there are any further issues please reopen.

@jan-molak
Copy link
Contributor

3.29.2 works well, thanks @mikekucera 🚀

jan-molak added a commit to serenity-js/serenity-js.org that referenced this issue Jul 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A bug in the code of Cytoscape.js
Projects
None yet
Development

No branches or pull requests

7 participants