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

Issues with importing from 'ollama/browser' #151

Open
matthiasgeihs opened this issue Oct 16, 2024 · 5 comments
Open

Issues with importing from 'ollama/browser' #151

matthiasgeihs opened this issue Oct 16, 2024 · 5 comments

Comments

@matthiasgeihs
Copy link

I have an Electron Webpack/TypeScript project created with Electron Forge.
This is the default tsconfig.json in this case: webpack-typescript/tsconfig.json.

I'm trying to use ollama-js within that project and having trouble importing from ollama/browser (i.e., via import ollama from 'ollama/browser';).

The first error I get is the following:

Cannot find module 'ollama/browser' or its corresponding type declarations.
  There are types at '/Users/matthias/source/mg/quick-assistant/node_modules/ollama/dist/browser.d.mts', but this result could not be resolved under your current 'moduleResolution' setting. Consider updating to 'node16', 'nodenext', or 'bundler'.ts(2307)

Once I start changing moduleResolution to something other than the default Node, I get other errors (e.g., An unhandled rejection has occurred inside Forge: Error: Unable to use specified module loaders for ".ts".).

I wonder, is this something about the template project setup? Or is there maybe a problem with the ollama-js/browser packaging? 🤔

@matthiasgeihs
Copy link
Author

Note that compilation works with import ollama from 'ollama/dist/browser.cjs';, but this is a hack and we shouldn't need to refer explicitly to the dist folder.

@hopperelec
Copy link
Contributor

Seems like the same issue as #104, but their fix was changing the module and moduleresolution

@matthiasgeihs
Copy link
Author

matthiasgeihs commented Oct 16, 2024

Seems like the same issue as #104, but their fix was changing the module and moduleresolution

Thanks for the pointer, @hopperelec. Turns out that moduleResolution: NodeNext kind of also works for me. I was getting some errors at first, but upgrading typescript from v4 to v5 made these go away. Not sure if this might break some stuff with electron under the hood? Other problem is that eslint still can't find the package and complains about that.

So, in summary, moduleResolution: NodeNext kind of works, but not all the way through. Would be nice if import ollama from 'ollama/browser' would just work out of the box with moduleResolution: Node and module: CommonJS.

Maybe somebody with more TypeScript/WebPack experience can help?

@hopperelec
Copy link
Contributor

Yes, this definitely seems like something which could be improved with ollama-js, but I'm not experienced enough with Webpack and the tsconfig to know what the issue is, sadly.

@preston
Copy link

preston commented Oct 31, 2024

This is coming up with @langchain/ollama as they explicitly import "olamma/browser" and not "ollama/dist/browser", so I would think it's a big headache for a lot of people. In the interim, is there an older version of ollama-js that doesn't have this issue?

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