[GH-ISSUE #4516] Ollama: running Vite in production mode fails #2831

Open
opened 2026-04-12 13:10:20 -05:00 by GiteaMirror · 10 comments
Owner

Originally created by @ejgutierrez74 on GitHub (May 18, 2024).
Original GitHub issue: https://github.com/ollama/ollama/issues/4516

Originally assigned to: @BruceMacD on GitHub.

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

Originally created by @ejgutierrez74 on GitHub (May 18, 2024). Original GitHub issue: https://github.com/ollama/ollama/issues/4516 Originally assigned to: @BruceMacD on GitHub. ### 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
GiteaMirror added the jsbug labels 2026-04-12 13:10:20 -05:00
Author
Owner

@thinkverse commented on GitHub (May 18, 2024):

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

<!-- gh-comment-id:2119012684 --> @thinkverse commented on GitHub (May 18, 2024): This seems like an issue that should be created on https://github.com/ollama/ollama-js instead.
Author
Owner

@pdevine commented on GitHub (May 18, 2024):

cc @BruceMacD

<!-- gh-comment-id:2119019888 --> @pdevine commented on GitHub (May 18, 2024): cc @BruceMacD
Author
Owner

@ejgutierrez74 commented on GitHub (May 19, 2024):

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

<!-- gh-comment-id:2119176192 --> @ejgutierrez74 commented on GitHub (May 19, 2024): 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
Author
Owner

@thinkverse commented on GitHub (May 19, 2024):

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

<!-- gh-comment-id:2119208275 --> @thinkverse commented on GitHub (May 19, 2024): > 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](https://docs.github.com/en/issues/tracking-your-work-with-issues/transferring-an-issue-to-another-repository#transferring-an-open-issue-to-another-repository) manually. 👍
Author
Owner

@imareo commented on GitHub (May 26, 2024):

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.

<!-- gh-comment-id:2132248922 --> @imareo commented on GitHub (May 26, 2024): > 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.
Author
Owner

@ejgutierrez74 commented on GitHub (May 26, 2024):

The link you provided is broken....

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

<!-- gh-comment-id:2132258846 --> @ejgutierrez74 commented on GitHub (May 26, 2024): The link you provided is broken.... But the thing is that in dev mode it hasnt any problems....
Author
Owner

@imareo commented on GitHub (May 26, 2024):

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

<!-- gh-comment-id:2132268294 --> @imareo commented on GitHub (May 26, 2024): vite build dist for browser, for run dev mode used nodejs
Author
Owner

@YugandharrPatil commented on GitHub (Jul 22, 2024):

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)

<!-- gh-comment-id:2242474266 --> @YugandharrPatil commented on GitHub (Jul 22, 2024): 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)
Author
Owner

@congyaqwq commented on GitHub (Jan 3, 2025):

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

<!-- gh-comment-id:2568662744 --> @congyaqwq commented on GitHub (Jan 3, 2025): import ollama from 'ollama/browser' instead of 'ollama'
Author
Owner

@ejgutierrez74 commented on GitHub (Jan 9, 2025):

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

???

<!-- gh-comment-id:2579648356 --> @ejgutierrez74 commented on GitHub (Jan 9, 2025): > vite build dist for browser, for run dev mode used nodejs ???
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#2831