ollama / ollama-js

Ollama JavaScript library
https://ollama.com
MIT License
2.28k stars 179 forks source link

Ollama 0.5.7 introduce a BREAKING CHANAGE for browser usage #132

Closed arvinxx closed 3 months ago

arvinxx commented 3 months ago

We use ollama-js in browser and edge runtime. But 0.5.7 seems intro the node into these cases, which cause the vercel build error:

image

here is the error stack:

node:fs
Module build failed: UnhandledSchemeError: Reading from "node:fs" is not handled by plugins (Unhandled scheme).
Webpack supports "data:" and "file:" URIs by default.
You may need an additional plugin to handle "node:" URIs.
    at /vercel/path0/node_modules/next/dist/compiled/webpack/bundle5.js:28:401757
    at Hook.eval [as callAsync] (eval at create (/vercel/path0/node_modules/next/dist/compiled/webpack/bundle5.js:13:28858), <anonymous>:6:1)
    at Object.processResource (/vercel/path0/node_modules/next/dist/compiled/webpack/bundle5.js:28:401682)
    at processResource (/vercel/path0/node_modules/next/dist/compiled/loader-runner/LoaderRunner.js:1:5308)
    at iteratePitchingLoaders (/vercel/path0/node_modules/next/dist/compiled/loader-runner/LoaderRunner.js:1:4667)
    at runLoaders (/vercel/path0/node_modules/next/dist/compiled/loader-runner/LoaderRunner.js:1:8590)
    at NormalModule._doBuild (/vercel/path0/node_modules/next/dist/compiled/webpack/bundle5.js:28:401544)
    at NormalModule.build (/vercel/path0/node_modules/next/dist/compiled/webpack/bundle5.js:28:403572)
    at /vercel/path0/node_modules/next/dist/compiled/webpack/bundle5.js:28:82055
    at NormalModule.needBuild (/vercel/path0/node_modules/next/dist/compiled/webpack/bundle5.js:28:407670)
Import trace for requested module:
node:fs
./node_modules/fetch-blob/from.js
./node_modules/node-fetch/src/index.js
./node_modules/ollama/dist/shared/ollama.7d273fc8.mjs
./node_modules/ollama/dist/browser.mjs
./src/libs/agent-runtime/ollama/index.ts
./src/libs/agent-runtime/index.ts
./src/app/api/chat/models/[provider]/route.ts

here is the reproduction repo and branch: https://github.com/lobehub/lobe-chat/tree/reproduction/ollama-0.5.7

pnpm i

pnpm run build

I think this issue is introduced by https://github.com/ollama/ollama-js/pull/125 , I suggest to revert this change.

jmorganca commented 3 months ago

This should be fixed in https://github.com/ollama/ollama-js/releases/tag/v0.5.8 while a longer term solution is found. Thanks for the issue!