ollama / ollama-js

Ollama JavaScript library
https://ollama.com
MIT License
2.24k stars 175 forks source link

node_modules/ollama/dist/index.mjs (2:13): "promises" is not exported by "node_modules/node-stdlib-browser/esm/mock/empty.js", imported by "node_modules/ollama/dist/index.mjs". #141

Open czwlkjgzs opened 2 months ago

czwlkjgzs commented 2 months ago
x Build failed in 9.38s
error during build:
node_modules/ollama/dist/index.mjs (2:13): "promises" is not exported by "node_modules/node-stdlib-browser/esm/mock/empty.js", imported by "node_modules/ollama/dist/index.mjs".
file: D:/myCodes/projectCodes/czwl-ollama-webui/node_modules/ollama/dist/index.mjs:2:13

1: import { O as Ollama$1, h as head, p as post } from './shared/ollama.5360ad67.mjs';
2: import fs, { promises, createReadStream } from 'fs';
                ^
3: import { resolve, join, dirname } from 'path';
4: import { createHash } from 'crypto';

    at getRollupError (file:///D:/myCodes/projectCodes/czwl-ollama-webui/node_modules/rollup/dist/es/shared/parseAst.js:392:41)
    at error (file:///D:/myCodes/projectCodes/czwl-ollama-webui/node_modules/rollup/dist/es/shared/parseAst.js:388:42)
    at Module.error (file:///D:/myCodes/projectCodes/czwl-ollama-webui/node_modules/rollup/dist/es/shared/node-entry.js:13967:16)
    at Module.traceVariable (file:///D:/myCodes/projectCodes/czwl-ollama-webui/node_modules/rollup/dist/es/shared/node-entry.js:14414:29)
    at ModuleScope.findVariable (file:///D:/myCodes/projectCodes/czwl-ollama-webui/node_modules/rollup/dist/es/shared/node-entry.js:12121:39)
    at ChildScope.findVariable (file:///D:/myCodes/projectCodes/czwl-ollama-webui/node_modules/rollup/dist/es/shared/node-entry.js:7467:38)
    at ClassBodyScope.findVariable (file:///D:/myCodes/projectCodes/czwl-ollama-webui/node_modules/rollup/dist/es/shared/node-entry.js:7467:38)
    at ChildScope.findVariable (file:///D:/myCodes/projectCodes/czwl-ollama-webui/node_modules/rollup/dist/es/shared/node-entry.js:7467:38)
    at ChildScope.findVariable (file:///D:/myCodes/projectCodes/czwl-ollama-webui/node_modules/rollup/dist/es/shared/node-entry.js:7467:38)
    at FunctionScope.findVariable (file:///D:/myCodes/projectCodes/czwl-ollama-webui/node_modules/rollup/dist/es/shared/node-entry.js:7467:38)

I've already use import ollama from ollama/browser. But the error occured when I try vite build.

this is my vite.config.js

import {fileURLToPath, URL} from 'node:url'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import {ElementPlusResolver} from 'unplugin-vue-components/resolvers'
import {defineConfig} from 'vite'
import vue from '@vitejs/plugin-vue'
import {nodePolyfills} from "vite-plugin-node-polyfills"

// https://vitejs.dev/config/
export default defineConfig({
    plugins: [
        [vue()],
        AutoImport({
            imports: ['vue', 'vue-router'],
            // dts: 'src/auto-import.d.ts',
            dts: 'auto-import.d.ts',
            resolvers: [ElementPlusResolver()],
        }),
        Components({
            resolvers: [ElementPlusResolver()],
        }),
        nodePolyfills({protocolImports: true}),
    ],
    resolve: {
        alias: {
            '@': fileURLToPath(new URL('./src', import.meta.url))
        },
    }
})
czwlkjgzs commented 2 months ago

I've solved this problem. My vite version is 5.x, So I have to use --force parameter npm install vite-plugin-node-stdlib-browser --force

if the suffix of the vite config file is .ts, you need to change .ts to .js. Then configure as follows.

import nodeStdlibBrowser from 'vite-plugin-node-stdlib-browser';

export default defineConfig({
    plugins: [
       ...
        nodePolyfills({protocolImports: true}),
        nodeStdlibBrowser(),
       ...
    ],
})

There is still a problem here.

When I try vite build. Everything is ok. But when I try vite. I have to comment out nodePolyfills({protocolImports: true}),