alewin/useWorker

Bad isoworker import

jer-sen opened this issue · 10 comments

[Required] Describe the bug
isoworker dependency does not provide a default import so isoworker.createContext raises an error from index.mjs.
I face this bug while using expo-camera bar code scanner on Web.

[Required] Expected behavior
No error.

isoworker should be imported as import * as isoworker from 'isoworker' here

import isoworker from 'isoworker'

At least until isoworker has a default export cf 101arrowz/isoworker#2

Yes, as I mentioned in the original PR, that needs to be import { createContext } from 'isoworker'.

Yes but I think it won't work without the full path. The solution should be:

import { createContext } from 'isoworker/esm/browser.js'

But it's an extraneous import so it's dangerous (if isoworker build change).
That's why I asked a default export to isoworker for a perfect long term solution.

Yes but I think it won't work without the full path. The solution should be:

import { createContext } from 'isoworker/esm/browser.js'

But it's an extraneous import so it's dangerous (if isoworker build change).
That's why I asked a default export to isoworker for a perfect long term solution.

I agree, for now I am temporarily removing isoworker and the localdeps feature, I'll release the new version very soon

No, the pure isoworker import works. The "exports" field enables it to automatically find "esm/browser.js", and this should function with all bundlers (Rollup, Parcel, Webpack, etc.) I have tested this extensively and have done this before in 101arrowz/fflate, so I'm sure it works. At worst it needs some bundler config changed.

With from 'isoworker' esm/browser.js is found but since the import is not a precise file, only default export can be reached (which is undefined). Trying to import a specific export leads to error Can't import the named export 'createContext' from non EcmaScript module (only default export is available) cf #98 (comment)

With from 'isoworker/esm/browser.js' esm/browser.js is also found and since the import is a precise file, any export can be reached (especially createContext).

I see, so it's an issue with the bundler config that is a bit difficult to change. In that case, does import { createContext } from 'fflate/browser' work? I'm guaranteeing that fflate/browser remains stable for browser imports, so if it works that's all that's necessary.

When will this be fixed so we can get the local dependencies back?

If useWorker is configured to use the ESM export from isoworker, rather than letting the bundler decide to use the CommonJS one, it will work properly.

Is this still being worked on? Or is there a workaround?