hpcc-js-wasm: SyntaxError: Named export 'graphviz' not found.

After having adopted type=module for d3-graphviz like D3 version 7 has, I get the following error when trying to npm run test for d3-graphviz using hpcc-js/wasm version 1.15.5 or later:

file:///home/magjac/d3-graphviz/src/dot.js:1
import { graphviz } from "@hpcc-js/wasm";
         ^^^^^^^^
SyntaxError: Named export 'graphviz' not found. The requested module '@hpcc-js/wasm' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from '@hpcc-js/wasm';
const { graphviz } = pkg;

    at ModuleJob._instantiate (node:internal/modules/esm/module_job:123:21)
    at async ModuleJob.run (node:internal/modules/esm/module_job:189:5)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:533:24)
    at async importModuleDynamicallyWrapper (node:internal/vm/module:438:15)
    at async formattedImport (/home/magjac/d3-graphviz/node_modules/mocha/lib/nodejs/esm-utils.js:7:14)
    at async Object.exports.requireOrImport (/home/magjac/d3-graphviz/node_modules/mocha/lib/nodejs/esm-utils.js:38:28)
    at async Object.exports.loadFilesAsync (/home/magjac/d3-graphviz/node_modules/mocha/lib/nodejs/esm-utils.js:91:20)
    at async singleRun (/home/magjac/d3-graphviz/node_modules/mocha/lib/cli/run-helpers.js:125:3)
    at async Object.exports.handler (/home/magjac/d3-graphviz/node_modules/mocha/lib/cli/run.js:370:5)

Am I importing this incorrectly?

It works fine with version 1.15.4.

For background and details of the D3 change, see https://github.com/d3/d3/issues/3469 and https://github.com/d3/d3/issues/3501.

npm run build works without problems.

My system:

$ npm --version
8.15.0
$ node --version
v16.17.1
$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 22.04.1 LTS
Release:	22.04
Codename:	jammy

See https://github.com/magjac/d3-graphviz/pull/242 for details.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 18 (15 by maintainers)

Commits related to this issue

Most upvoted comments

My two cents:

Sorry for the late reply. Yes, this problem is now gone. Thanks a lot.

I have some other problems that I need to investigate further, but they might very well be my own.

I tested again by checking out the https://github.com/magjac/d3-graphviz/pull/242 PR and using the newly released version of @hpcc-js/wasm (1.18.0) and it seems the issue is fixed, the tests are able to import and use the module. cc @magjac

I can reproduce this locally - but the only quick workaround I would have is to bundle my lib into yours (i.e. don’t make it external). Also your marking you package as being a “module”, but your generating “umd” code? I suspect if I rolled back my “exports” section and just used “main” and “module” pointing to the browser version, then it might also work - I need to play more.