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

Raymond Tang Raymond Tang 0 657 1.78 index 6/23/2024

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

javascript node.js

Join the Discussion

View or add your thoughts below

Comments