ollama-js
ollama-js copied to clipboard
Issues with importing `from 'ollama/browser'`
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? 🤔
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.
Seems like the same issue as https://github.com/ollama/ollama-js/issues/104, but their fix was changing the module and moduleresolution
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?
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.
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?
Any updates here?
Any updates here?
Not really. Using the "import from ollama/dist" hack as described above.
// Explicit reference to `dist` needed because of packaging problem with `ollama/browser`.
import ollama, { GenerateResponse } from "ollama/dist/browser.cjs";
https://github.com/matthiasgeihs/smart-lookup/blob/01b2d0b8776c1b6d9229e211dfdbe14b1bc0242d/src/renderer.ts#L4