qq15725/modern-rembg

Error _onnxruntimeWeb.env is undefined

Closed this issue · 1 comments

Hi!

Thank you for creating and sharing such a great library!
I try to integrate it into an existing project but get the following error:

Uncaught (in promise) TypeError: _onnxruntimeWeb.env is undefined
    init index.mjs:290
    removeBackground index.mjs:316

The code is super simple:

const handleFileChange = async (e: ChangeEvent<HTMLInputElement>) => {
  const file: File | undefined = e.target.files?.[0];
  if (file) {
    const blob: Blob = await removeBackground(file);
    //...
  }
};

modern-rembg version 0.1.2.

Could you please suggest a fix?

The problem was related to Parcel bundler.

Adding the following to the package.json solves the issue:

{
  "@parcel/resolver-default": {
    "packageExports": true
  }
}

That's because onnxruntime-web uses exports in package-json: https://github.com/microsoft/onnxruntime/blob/main/js/web/package.json#L70