ollama icon indicating copy to clipboard operation
ollama copied to clipboard

Ollama: running Vite in production mode fails

Open ejgutierrez74 opened this issue 1 year ago • 4 comments

What is the issue?

Im developing web app for educational purpose. I use React + Vite. Till now in development mode im not facing great problems.... But now i have tried to run in production mode and got the error below: h

vite v5.2.10 building for production...
[plugin:vite:resolve] [plugin vite:resolve] Module "fs" has been externalized for browser compatibility, imported by "/home/eduardo/Descargas/workshop-react/node_modules/ollama/dist/index.mjs". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] [plugin vite:resolve] Module "path" has been externalized for browser compatibility, imported by "/home/eduardo/Descargas/workshop-react/node_modules/ollama/dist/index.mjs". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] [plugin vite:resolve] Module "crypto" has been externalized for browser compatibility, imported by "/home/eduardo/Descargas/workshop-react/node_modules/ollama/dist/index.mjs". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] [plugin vite:resolve] Module "os" has been externalized for browser compatibility, imported by "/home/eduardo/Descargas/workshop-react/node_modules/ollama/dist/index.mjs". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
✓ 1052 modules transformed.
x Build failed in 1.49s
error during build:
RollupError: node_modules/ollama/dist/index.mjs (2:13): "promises" is not exported by "__vite-browser-external", imported by "node_modules/ollama/dist/index.mjs".
file: /home/eduardo/Descargas/workshop-react/node_modules/ollama/dist/index.mjs:2:13
1: import { O as Ollama$1, h as head, p as post } from './shared/ollama.14e58652.mjs';
2: import fs, { promises, createReadStream } from 'fs';
                ^
3: import { resolve, join, dirname } from 'path';
4: import { createHash } from 'crypto';
    at getRollupError (file:///home/eduardo/Descargas/workshop-react/node_modules/vite/node_modules/rollup/dist/es/shared/parseAst.js:394:41)
    at error (file:///home/eduardo/Descargas/workshop-react/node_modules/vite/node_modules/rollup/dist/es/shared/parseAst.js:390:42)
    at Module.error (file:///home/eduardo/Descargas/workshop-react/node_modules/vite/node_modules/rollup/dist/es/shared/node-entry.js:13860:16)
    at Module.traceVariable (file:///home/eduardo/Descargas/workshop-react/node_modules/vite/node_modules/rollup/dist/es/shared/node-entry.js:14308:29)
    at ModuleScope.findVariable (file:///home/eduardo/Descargas/workshop-react/node_modules/vite/node_modules/rollup/dist/es/shared/node-entry.js:11989:39)
    at ChildScope.findVariable (file:///home/eduardo/Descargas/workshop-react/node_modules/vite/node_modules/rollup/dist/es/shared/node-entry.js:7432:38)
    at ClassBodyScope.findVariable (file:///home/eduardo/Descargas/workshop-react/node_modules/vite/node_modules/rollup/dist/es/shared/node-entry.js:7432:38)
    at ChildScope.findVariable (file:///home/eduardo/Descargas/workshop-react/node_modules/vite/node_modules/rollup/dist/es/shared/node-entry.js:7432:38)
    at ChildScope.findVariable (file:///home/eduardo/Descargas/workshop-react/node_modules/vite/node_modules/rollup/dist/es/shared/node-entry.js:7432:38)
    at FunctionScope.findVariable (file:///home/eduardo/Descargas/workshop-react/node_modules/vite/node_modules/rollup/dist/es/shared/node-entry.js:7432:38)

As for Vite is a problem that should be fixed by ollama ( the library) :https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility

Just if not clear: npm run dev works, but when i tried npm run build....i got the error above.

Hope this could be fixed soon.

Thanks

OS

No response

GPU

No response

CPU

No response

Ollama version

0.1.37

ejgutierrez74 avatar May 18 '24 18:05 ejgutierrez74

This seems like an issue that should be created on https://github.com/ollama/ollama-js instead.

thinkverse avatar May 18 '24 21:05 thinkverse

cc @BruceMacD

pdevine avatar May 18 '24 22:05 pdevine

Then should i post in ollama-js ?? But i only installed ollama ( npm install ollama) in my project. Not ollamajs.... Hope this could be fixed soon... Thanks

ejgutierrez74 avatar May 19 '24 09:05 ejgutierrez74

Then should i post in ollama-js ?? But i only installed ollama ( npm install ollama) in my project. Not ollamajs....

ollama/ollama-js is the repository for the npm package. This repository ollama/ollama, is for the actual Ollama service you install on your computer or server, not the npm package. It's for the service the npm package interacts with.

And you don't have to post it again there, the Ollama team can transfer the issue over manually. 👍

thinkverse avatar May 19 '24 11:05 thinkverse

import fs, { promises, createReadStream } from 'fs';

you can't use 'fs/promises' inside browser.

maybe help this: https://github.com/vitejs/vite/discussions/8799#discussioncomment-8191565 in my case I rewrite code using api.

imareo avatar May 26 '24 14:05 imareo

The link you provided is broken....

But the thing is that in dev mode it hasnt any problems....

ejgutierrez74 avatar May 26 '24 15:05 ejgutierrez74

vite build dist for browser, for run dev mode used nodejs

imareo avatar May 26 '24 15:05 imareo

i have an alternative solution but it only works with nextjs.

put the api call in a file use the "use server" directive on top. this way, the issue completely goes away for reasons stated above (code run in a node node env rather than on browser)

YugandharrPatil avatar Jul 22 '24 09:07 YugandharrPatil

import ollama from 'ollama/browser' instead of 'ollama'

congyaqwq avatar Jan 03 '25 03:01 congyaqwq

vite build dist for browser, for run dev mode used nodejs

???

ejgutierrez74 avatar Jan 09 '25 09:01 ejgutierrez74