catdad-experiments / catdad-experiments/libheif-js

Cannot import 'libheif-js/wasm' correctly on Node/Express (Relavite path issue)

Open
#45 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
118
Forks
10
Avg merge
2h 3m
Merged PRs (30d)
1

Description

this statement:

```javascript
import libheif from 'libheif-js/wasm';
// OR
import libheif from 'libheif-js/wasm.js';
```

does not work. the package exists in node_modules, but node can't find it.

Explicitly typing:

```javascript
import libheif from 'libheif-js/libheif-wasm/libheif.js';
```

Results in wasm binary not getting passed to the 'libheif-wasm/libheif.js' and thus not getting initialized correctly, throwing `TypeError: libheif.HeifDecoder is not a constructor`

But, trying to load it using this method directly:

```javascript
import { createRequire } from 'module';
import fs from 'fs';

// Weird relative path import bug fix
const wasmBinary = fs.readFileSync('./node_modules/libheif-js/libheif-wasm/libheif.wasm');
const libheif = createRequire(import.meta.url)('libheif-js/libheif-wasm/libheif.js')({ wasmBinary });
```

Works as intended, but a bit cluttersome

The issue is that the module tries to load the wasm binary on the node/express root like `express-app-name/libheif-wasm/libheif.wasm` instead of `express-app-name/node_modules/libheif-js/libheif-wasm/libheif.wasm`

Existed on 1.19.8 (first time using it) and also exists on 1.23.2 released recently.

To reproduce, run `npm install libheif-js` and try to reference it

Running on Node LTS v24.20.0 & Express ^5.2.1, Windows 11 25H2

Contributor guide

No contributing guide indexed for this repository

Research direction

Reproduce the failure after installing libheif-js, then inspect the package entry point and libheif-wasm/libheif.js, including how it locates libheif.wasm. Compare the normal imports with the createRequire workaround and verify that the documented import initializes HeifDecoder under Node/Express.

Written by the indexing model from the issue text.

Assessment

Tech stack
express, javascript, node.js, wasm
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.