svgdotjs / svgdom

Straightforward DOM implementation to make SVG.js run headless on Node.js
MIT License
269 stars 53 forks source link

'fontkit' does not provide an export named 'openSync' #115

Closed fhirter closed 10 months ago

fhirter commented 11 months ago

i am using svgdom to run tests using jest.

Until svgdom version 0.1.14 the following code was working. It is a test file run by jest (29.7.0): node --experimental-vm-modules jest

// parcel.test.js
import crypto from "crypto";
import {createSVGWindow} from "svgdom";
import {registerWindow} from "@svgdotjs/svg.js";
import {expect, test} from "@jest/globals";

// register window and document
const window = createSVGWindow()
const document = window.document
registerWindow(window, document)

In version 0.1.17. it fails with:

    SyntaxError: The requested module 'fontkit' does not provide an export named 'openSync'

      at Runtime.linkAndEvaluateModule (node_modules/jest-runtime/build/index.js:708:5)
Fuzzyma commented 11 months ago

Running your code gives no output. Can you add more context so it shows the error?

fhirter commented 11 months ago

Running your code gives no output. Can you add more context so it shows the error?

updated the issue. Its run by jest test runner.

hope that helps replicating it.

Fuzzyma commented 11 months ago

no, that doesnt really help. I pushed a possible fix. Please try the current master version and report if it works

fhirter commented 11 months ago

no, that doesnt really help. I pushed a possible fix. Please try the current master version and report if it works

I did your changes manually and the error was resolved.

But another error appears:

    ReferenceError: TextDecoder is not defined

      at node_modules/fontkit/dist/src/utils.js:28:29
Fuzzyma commented 11 months ago

This seems to be on fontkits side now. jest doesnt work great with esm modules. You might want to read trough https://jestjs.io/docs/ecmascript-modules

mattsputnikdigital commented 11 months ago

Im getting this building a React app in Vite. The master branch fixes the issue so the possible fix does work for build issues.

No matching export in "node_modules/fontkit/dist/browser-module.mjs" for import "openSync"

node_modules/svgdom/src/config.js:2:9:
  2 │ import { openSync } from 'fontkit'
Fuzzyma commented 11 months ago

@mattsputnikdigital did you try current master? Please report back if it works

mattsputnikdigital commented 11 months ago

@Fuzzyma yes the master branch fixes the problem so you are good to include that fix in a new release.

Fuzzyma commented 10 months ago

nice. thanks for letting me know

Fuzzyma commented 10 months ago

released as 0.1.18