kekee000 / fonteditor-core

fonteditor core functions
MIT License
355 stars 66 forks source link

Doesn't work with Node v18 - TypeError : Failed to parse URL from .../woff2/woff2.wasm #61

Closed davcri closed 1 year ago

davcri commented 1 year ago

Description

I got this error either by including the library as a dependency in one of my projects, either issuing npm run test:browser from the fonteditor-core root.

Operating System: OSX 13.2.1 Node: v18.x (via nvm, but it shouldn't matter)

image


  adjustttf
    ✓ adjust ttf

  font
    1) "before all" hook

/Users/davide.cristini/libs-src/fonteditor-core/woff2/woff2.js:8
"use strict";var Module=typeof Module!=="undefined"?Module:{};var moduleOverrides={};var key;for(key in Module){if(Module.hasOwnProperty(key)){moduleOverrides[key]=Module[key]}}var arguments_=[];var thisProgram="./this.program";var quit_=function(status,toThrow){throw toThrow};var ENVIRONMENT_IS_WEB=false;var ENVIRONMENT_IS_WORKER=false;var ENVIRONMENT_IS_NODE=false;var ENVIRONMENT_HAS_NODE=false;var ENVIRONMENT_IS_SHELL=false;ENVIRONMENT_IS_WEB=typeof window==="object";ENVIRONMENT_IS_WORKER=typeof importScripts==="function";ENVIRONMENT_HAS_NODE=typeof process==="object"&&typeof process.versions==="object"&&typeof process.versions.node==="string";ENVIRONMENT_IS_NODE=ENVIRONMENT_HAS_NODE&&!ENVIRONMENT_IS_WEB&&!ENVIRONMENT_IS_WORKER;ENVIRONMENT_IS_SHELL=!ENVIRONMENT_IS_WEB&&!ENVIRONMENT_IS_NODE&&!ENVIRONMENT_IS_WORKER;if(Module["ENVIRONMENT"]){throw new Error("Module.ENVIRONMENT has been deprecated. To force the environment, use the ENVIRONMENT compile-time option (for example, -s ENVIRONMENT=web or -s ENVIRONMENT=node)")}var scriptDirectory="";function locateFile(path){if(Module["locateFile"]){return Module["locateFile"](path,scriptDirectory)}return scriptDirectory+path}var read_,readAsync,readBinary,setWindowTitle;if(ENVIRONMENT_IS_NODE){scriptDirectory=__dirname+"/";var nodeFS;var nodePath;read_=function shell_read(filename,binary){var ret;if(!nodeFS)nodeFS=require(["fs"].join());if(!nodePath)nodePath=require(["path"].join());filename=nodePath["normalize"](filename);ret=nodeFS["readFileSync"](filename);return binary?ret:ret.toString()};readBinary=function readBinary(filename){var ret=read_(filename,true);if(!ret.buffer){ret=new Uint8Array(ret)}assert(ret.buffer);return ret};if(process["argv"].length>1){thisProgram=process["argv"][1].replace(/\\/g,"/")}arguments_=process["argv"].slice(2);process["on"]("uncaughtException",function(ex){if(!(ex instanceof ExitStatus)){throw ex}});process["on"]("unhandledRejection",abort); 
/**...*/

abort(TypeError: Failed to parse URL from /Users/davide.cristini/libs-src/fonteditor-core/woff2/woff2.wasm) at Error
    at jsStackTrace (/Users/davide.cristini/libs-src/fonteditor-core/woff2/woff2.js:8:22389)
    at stackTrace (/Users/davide.cristini/libs-src/fonteditor-core/woff2/woff2.js:8:22560)
    at process.abort (/Users/davide.cristini/libs-src/fonteditor-core/woff2/woff2.js:8:18310)
    at process.emit (node:events:514:28)
    at emit (node:internal/process/promises:149:20)
    at processPromiseRejections (node:internal/process/promises:283:27)
    at process.processTicksAndRejections (node:internal/process/task_queues:96:32)
(Use `node --trace-uncaught ...` to show where the exception was thrown)

Node.js v18.17.1

Some investigation

Seems like an issue with woff2.js?

Workaround

This issue is not present with Node v16.x.

image

kekee000 commented 1 year ago

fixed for node 17+, use arraybuffer instead of fetch api

davcri commented 1 year ago

Thanks for the fix @kekee000 I confirm that the tests run fine with the latest commit.