transformers.js icon indicating copy to clipboard operation
transformers.js copied to clipboard

fix: resolve webpack import.meta warning in browser extension

Open devlux76 opened this issue 7 months ago • 3 comments

  • Add parser configuration to disable import.meta parsing in webpack
  • Suppress critical dependency warnings from @huggingface/transformers
  • Add Node.js fallbacks for browser compatibility (fs, path, url)
  • Ensures clean build without warnings while maintaining ML functionality
  • Extension now builds successfully for both development and production

Resolves webpack 5 compatibility issue with Transformers.js library when bundling for browser extension environment.

devlux76 avatar May 27 '25 13:05 devlux76

Hi there 👋 thanks for the PR!

We're in the process of moving our examples to https://github.com/huggingface/transformers.js-examples/tree/main/browser-extension; can you check if this is still an issue in that example? Thanks!

xenova avatar May 30 '25 19:05 xenova

Hi! @xenova I just checked, and it is still an issue. I ran current "transformers.js-examples" and got this build error:

build.log

I also tried to apply changes suggested in this PR. the PR itself works, but it is missing the lines below when compared to the current "-extensions" solution.

    alias: {
      "@huggingface/transformers": path.resolve(
        __dirname,
        "node_modules/@huggingface/transformers",
      ),
    },

when this is added (to match current "transformers.js-examples"), the error in the build.log above appears again.

vindex10 avatar Nov 01 '25 23:11 vindex10

there is actually a pull request in transformer.js-examples to fix this example:

https://github.com/huggingface/transformers.js-examples/pull/71

vindex10 avatar Nov 02 '25 12:11 vindex10