-
Notifications
You must be signed in to change notification settings - Fork 22
Open
Description
The current release package seems to be broken. I did manage to use the package with TypeScript since it somehow miraculously transforms the code. However, I couldn't get my tests to work with ts-jest which made me research the issue.
In its current form Node.js crashes when you try to import the module.
$ node
Welcome to Node.js v16.13.0.
Type ".help" for more information.
> await import('graphviz-react')
(node:13519) 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)
/XXXXX/node_modules/graphviz-react/lib/Graphviz.js:1
import * as React from 'react';
^^^^^^
The Node.js crash can be fixed by adding "type": "module", to package.json. That will make basic importing work.
$ node
Welcome to Node.js v16.13.0.
Type ".help" for more information.
> await import('graphviz-react')
[Module: null prototype] {
Graphviz: [class Graphviz extends Component] {
count: 0,
defaultOptions: { fit: true, height: 500, width: 500, zoom: false }
},
default: [class Graphviz extends Component] {
count: 0,
defaultOptions: { fit: true, height: 500, width: 500, zoom: false }
}
}
However, fixing the package.json file did not fix my tests, so I continued my research.
Even after the fix, importing the package in ts-node still fails for some reason.
$ ts-node
> await import('graphviz-react')
Uncaught:
Error [ERR_REQUIRE_ESM]: require() of ES Module /XXXXX/node_modules/graphviz-react/lib/Graphviz.js not supported.
Instead change the require of Graphviz.js in null to a dynamic import() which is available in all CommonJS modules.
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at /XXXXX/<repl>.ts:4:14
at require (node:internal/modules/cjs/helpers:102:18)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1128:19)
at new NodeError (node:internal/errors:371:5)
at __node_internal_captureLargerStackTrace (node:internal/errors:464:5) {
code: 'ERR_REQUIRE_ESM'
}
Metadata
Metadata
Assignees
Labels
No labels