Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

webpack error migrating from 0.9.15 -> 0.9.16 #10

Closed
dbo opened this issue Aug 8, 2023 · 5 comments
Closed

webpack error migrating from 0.9.15 -> 0.9.16 #10

dbo opened this issue Aug 8, 2023 · 5 comments

Comments

@dbo
Copy link

dbo commented Aug 8, 2023

I get the following error with the latest version:

ERROR in ../../node_modules/@undecaf/zbar-wasm/dist/main.js 15:653-669
Module not found: Error: Can't resolve 'module' in '/myprj/node_modules/@undecaf/zbar-wasm/dist'
resolve 'module' in '/myprj/node_modules/@undecaf/zbar-wasm/dist'
  Parsed request is a module
  using description file: /myprj/node_modules/@undecaf/zbar-wasm/package.json (relative path: ./dist)
    Field 'browser' doesn't contain a valid alias configuration
    resolve as module
      looking for modules in /myprj/packages/sub-project/node_modules
        single file module
          using description file: /myprj/packages/sub-project/package.json (relative path: ./node_modules/module)
            no extension
              Field 'browser' doesn't contain a valid alias configuration
              /myprj/packages/sub-project/node_modules/module doesn't exist
            .js
              Field 'browser' doesn't contain a valid alias configuration
              /myprj/packages/sub-project/node_modules/module.js doesn't exist
        /myprj/packages/sub-project/node_modules/module doesn't exist
      looking for modules in /myprj/node_modules
        single file module
          using description file: /myprj/package.json (relative path: ./node_modules/module)
            no extension
              Field 'browser' doesn't contain a valid alias configuration
              /myprj/node_modules/module doesn't exist
            .js
              Field 'browser' doesn't contain a valid alias configuration
              /myprj/node_modules/module.js doesn't exist
        /myprj/node_modules/module doesn't exist
 @ ./out/file.js 1:0-51 14:22-35 21:22-35

webpack 5.88.2 compiled with 1 error in 1608 ms
@undecaf
Copy link
Owner

undecaf commented Aug 9, 2023

As a response to #9, I removed the Node polyfills from the ES module of zbar-wasm in 0.9.16 beause e.g. require() was polyfilled with an empty method; this caused loading of zbar-wasm as an ES module to fail in Node.

On the other side, it appears that you intend to use zbar-wasm as an ES module in a browser. The build with 0.9.16 fails because module is no longer polyfilled.

As for now, including module in your Webpack externals should solve the problem. The next version of zbar-wasm (which I am preparing) will include separate ES modules for Node and for browsers.

@borracciaBlu
Copy link

Similar issue here using next.

with 0.9.15 worked like a charm.
After the update to 0.9.16 i've got the following error:

./node_modules/@undecaf/zbar-wasm/dist/main.js
Module not found: Can't resolve 'module'

Please consider i did use the import syntax

import { scanImageData } from '@undecaf/zbar-wasm';

instead if i use require:

const { scanImageData } = require('@undecaf/zbar-wasm');

i've got:

./node_modules/@undecaf/zbar-wasm/dist/main.cjs
Module not found: Can't resolve 'fs'

@undecaf
Copy link
Owner

undecaf commented Aug 23, 2023

@borracciaBlu This appears to be the same situation as above: main.js is the ESM build of zbar-wasm without polyfills for the Node dependencies such as module and fs. If targeting a browser with ESM, these dependencies cannot be resolved.

Declaring module and/or fs as external for your bundler should solve the problem for now. In a browser environment, the code referencing module and fs in zbar-wasm is dead code anyway.

I am sorry for this mess in 0.9.16, and I am working on cleaning up the package structure and providing more bundling hints in the docs.

@undecaf undecaf closed this as completed in e1f11c9 Sep 3, 2023
@undecaf
Copy link
Owner

undecaf commented Sep 3, 2023

@dbo, @borracciaBlu zbar-wasm v0.10.0 should resolve this, although a different bundler configuration may be necessary.

Please feel free to re-open.

@borracciaBlu
Copy link

@undecaf working, thanks. I was able to get consistent results as in 0.9.15.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants