Resolve: "promises" is not exported by __vite-browser-external

Raymond Raymond event 2024-06-23 visibility 386
more_vert

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

More from Kontext
comment Comments
No comments yet.

Please log in or register to comment.

account_circle Log in person_add Register

Log in with external accounts