Resolve: "promises" is not exported by __vite-browser-external
Issue context
When using ollama-js
package in Vue + Vite project, the following error may show up when running nuxt generate
command:
ERROR Nuxt Build Error: node_modules/ollama/dist/index.mjs (2:13): "promises" is not exported by "__vite-browser-external", imported by "node_modules/ollama/dist/index.mjs".
Resolution
When running nuxt dev
, the above error will not throw out as it uses Node.js. When generating for browser, we can use polyfills to address the above issue.
npm install --save-dev vite-plugin-node-polyfills
Then add the plugin nodePolyfills
for Vite:
import yaml from "@rollup/plugin-yaml"
import { nodePolyfills } from 'vite-plugin-node-polyfills'
// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
devtools: { enabled: true},
ssr: false,
vite: {
plugins: [
yaml(),
nodePolyfills()
]
},
The above code snippet is for Nuxt. You can add to your vite.config.js
directly if you are not using any frameworks:
import { defineConfig } from 'vite'
import { nodePolyfills } from 'vite-plugin-node-polyfills'
export default defineConfig({
plugins: [
nodePolyfills(),
],
})
Ollama
For applications built with ollama-js with client side rendering, please import from 'ollama/browser
'.
info Last modified by Raymond 7 months ago
copyright
This page is subject to Site terms.
comment Comments
No comments yet.