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

[Bug] Cannot get transformer working in electron browser #410

Open
eatgrass opened this issue Nov 23, 2023 · 4 comments
Open

[Bug] Cannot get transformer working in electron browser #410

eatgrass opened this issue Nov 23, 2023 · 4 comments
Labels
bug Something isn't working

Comments

@eatgrass
Copy link

Describe the bug
A clear and concise description of what the bug is.

as described in the title

After debugging into the code, I found that the wrong runtime was selected which caused an undefined env property. This bug was also mentioned in issue #336.

https://github.com/xenova/transformers.js/blob/768a2e26d7f34746caa2b102f55dbd270c5d6f36/src/backends/onnx.js#L32

How to reproduce
Steps or a minimal working example to reproduce the behavior

Expected behavior
A clear and concise description of what you expected to happen.

Logs/screenshots
If applicable, add logs/screenshots to help explain your problem.

[transformerjs cannot electron browser
](env.js:60 Uncaught TypeError: Cannot read properties of undefined (reading 'wasm'))

Environment

  • Transformers.js version:
  • Browser (if applicable):
  • Operating system (if applicable):
  • Other:

Additional context
Add any other context about the problem here.

I removed the runtime env check condition in my local and then the transformer worked fine.

@eatgrass eatgrass added the bug Something isn't working label Nov 23, 2023
@xenova
Copy link
Collaborator

xenova commented Nov 23, 2023

I removed the runtime env check condition in my local and then the transformer worked fine.

Could you please try logging what the values for typeof process and process?.release?.name are? Also, which build tools are you using (if any)? FWIW, the electron example we have created seems to work correctly.

If you are able to provide a reproduction, that would help with the debugging process to :)

@eatgrass
Copy link
Author

eatgrass commented Nov 24, 2023

Sorry, I forgot to mention that I was developing an Obsidian plugin, so the code can only run in the browser environment. While debugging, I found that the actual value is node. I also came across another thread that discussed this issue.
#291 (comment)

@blackforestboi
Copy link

blackforestboi commented Dec 1, 2023

Running into the same issue. Any possibilty that it has to do with my project being written in typescript, whereas the electron example is in vanilla JS?
Another option is that webpack maybe gets in the way here smh?

I am getting this error:
Screenshot 2023-12-01 at 11 25 05

And this is my webpack config:

export const mainConfig: Configuration = {
  // existing configuration...
  entry: './src/index.ts',
  module: {
    rules,
  },
  resolve: {
    extensions: ['.js', '.ts', '.jsx', '.tsx', '.css', '.json'],
    alias: {
      "sharp$": false,
      "onnxruntime-node$": false,
    },
  },
  plugins: [
    new CopyWebpackPlugin({
      patterns: [
        { from: 'src/img', to: 'img' } // copies all files from 'src/img' to 'img'
      ],
    }),
    new Dotenv(),
  ],
};

Edit: Tried updating all electron dependencies to the ones I have in my project (which are newest versions) and your example still works, so can rule that out too.

@blackforestboi
Copy link

More updates: Made it work by removing webpack from my project

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants