Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build failed with vite build "promises" is not exported by "__vite-browser-external", imported by "node_modules/.pnpm/[email protected]/node_modules/ollama/dist/index.mjs". #189

Open
ejgutierrez74 opened this issue Jan 4, 2025 · 3 comments

Comments

@ejgutierrez74
Copy link

ejgutierrez74 commented Jan 4, 2025

I found this error: in vite in dev works fine, but when i make a run build to run a vite build i got:

Seems its an error in ollama-js side as written in Vite documentation: https://vite.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility

`vite v6.0.6 building for production...
[plugin:vite:resolve] [plugin vite:resolve] Module "fs" has been externalized for browser compatibility, imported by "/home/eduardo/WebstormProjects/MeuPacman/node_modules/.pnpm/[email protected]/node_modules/ollama/dist/index.mjs". See https://vite.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/WebstormProjects/MeuPacman/node_modules/.pnpm/[email protected]/node_modules/ollama/dist/index.mjs". See https://vite.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/WebstormProjects/MeuPacman/node_modules/.pnpm/[email protected]/node_modules/ollama/dist/index.mjs". See https://vite.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/WebstormProjects/MeuPacman/node_modules/.pnpm/[email protected]/node_modules/ollama/dist/index.mjs". See https://vite.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
✓ 79 modules transformed.
x Build failed in 654ms
error during build:
node_modules/.pnpm/[email protected]/node_modules/ollama/dist/index.mjs (2:13): "promises" is not exported by "__vite-browser-external", imported by "node_modules/.pnpm/[email protected]/node_modules/ollama/dist/index.mjs".
file: /home/eduardo/WebstormProjects/MeuPacman/node_modules/.pnpm/[email protected]/node_modules/ollama/dist/index.mjs:2:13

1: import { O as Ollama$1, h as head, p as post } from './shared/ollama.cddbc85b.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/WebstormProjects/MeuPacman/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/parseAst.js:396:41)
    at error (file:///home/eduardo/WebstormProjects/MeuPacman/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/parseAst.js:392:42)
    at Module.error (file:///home/eduardo/WebstormProjects/MeuPacman/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:15655:16)
    at Module.traceVariable (file:///home/eduardo/WebstormProjects/MeuPacman/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:16104:29)
    at ModuleScope.findVariable (file:///home/eduardo/WebstormProjects/MeuPacman/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:13887:39)
    at ChildScope.findVariable (file:///home/eduardo/WebstormProjects/MeuPacman/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:5306:38)
    at ClassBodyScope.findVariable (file:///home/eduardo/WebstormProjects/MeuPacman/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:5306:38)
    at ChildScope.findVariable (file:///home/eduardo/WebstormProjects/MeuPacman/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:5306:38)
    at ChildScope.findVariable (file:///home/eduardo/WebstormProjects/MeuPacman/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:5306:38)
    at FunctionScope.findVariable (file:///home/eduardo/WebstormProjects/MeuPacman/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:5306:38)
 ELIFECYCLE  Command failed with exit code 1.
`
@hexnaught
Copy link

Hey 👋

Vite is likely building a static site that may not be ran with node, so you don't have access to libraries that you require node for when trying to run with the built files.

Instead of importing from ollama, import from ollama/browser and it should work.

See the readme here: https://github.com/ollama/ollama-js?tab=readme-ov-file#browser-usage

@ejgutierrez74
Copy link
Author

whats the difference between ollama and ollama/browser...would this be compatible with Vercel deployment?

@hexnaught
Copy link

would this be compatible with Vercel deployment

Yes.

As for differences, the code is in this repo, you can see for yourself! 😅 tldr; the non browser import uses nodejs dependencies and is usable via running an app with nodejs. The browser import uses dependences and code compatible with a browser environment. Your Vite setup is likely packaging up a static build, so it can be ran with nginx, caddy, go, rust... whatever you want to serve HTML. So if you import modules that are from node, they won't work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants