ollama / ollama

Get up and running with Llama 3, Mistral, Gemma, and other large language models.
https://ollama.com
MIT License
70.7k stars 5.19k forks source link

Ollama: running Vite in production mode fails #4516

Open ejgutierrez74 opened 2 weeks ago

ejgutierrez74 commented 2 weeks ago

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

thinkverse commented 2 weeks ago

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

pdevine commented 2 weeks ago

cc @BruceMacD

ejgutierrez74 commented 1 week ago

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

thinkverse commented 1 week ago

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. 👍

imareo commented 6 days ago

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.

ejgutierrez74 commented 6 days ago

The link you provided is broken....

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

imareo commented 6 days ago

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