useWorker icon indicating copy to clipboard operation
useWorker copied to clipboard

Bad isoworker import

Open jer-sen opened this issue 4 years ago • 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 https://github.com/alewin/useWorker/blob/011d2a39be6c7e4113f81dc52c56a2b9ba8ed209/packages/useWorker/src/lib/createWorkerBlobUrl.ts#L1 At least until isoworker has a default export cf https://github.com/101arrowz/isoworker/issues/2

jer-sen avatar Mar 20 '21 18:03 jer-sen

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

101arrowz avatar Mar 21 '21 06:03 101arrowz

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.

jer-sen avatar Mar 21 '21 09:03 jer-sen

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

alewin avatar Mar 21 '21 10:03 alewin

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.

101arrowz avatar Mar 21 '21 10:03 101arrowz

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 https://github.com/alewin/useWorker/pull/98#discussion_r559237704

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).

jer-sen avatar Mar 21 '21 11:03 jer-sen

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.

101arrowz avatar Mar 21 '21 12:03 101arrowz

BTW, consider trying this solution out: https://github.com/reactioncommerce/reaction-component-library/issues/399#issuecomment-467860022

101arrowz avatar Mar 21 '21 12:03 101arrowz

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

rodrigonzalz avatar Jun 15 '21 09:06 rodrigonzalz

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.

101arrowz avatar Jun 15 '21 18:06 101arrowz

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

conor909 avatar Jul 08 '21 16:07 conor909