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

not compatible with CJS module #44

Closed
himself65 opened this issue Feb 7, 2024 · 3 comments
Closed

not compatible with CJS module #44

himself65 opened this issue Feb 7, 2024 · 3 comments

Comments

@himself65
Copy link

himself65 commented Feb 7, 2024

/Users/himself65/Library/Application Support/fnm/node-versions/v18.19.0/installation/lib/node_modules/ts-node/dist/index.js:851
            return old(m, filename);
                   ^
Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/himself65/Code/LlamaIndexTS/node_modules/.pnpm/[email protected]/node_modules/ollama/dist/index.js from /Users/himself65/Code/LlamaIndexTS/packages/core/dist/ServiceContext.js not supported.
Instead change the require of index.js in /Users/himself65/Code/LlamaIndexTS/packages/core/dist/ServiceContext.js to a dynamic import() which is available in all CommonJS modules.
    at require.extensions.<computed> [as .js] (/Users/himself65/Library/Application Support/fnm/node-versions/v18.19.0/installation/lib/node_modules/ts-node/dist/index.js:851:20)
    at Object.<anonymous> (/Users/himself65/Code/LlamaIndexTS/packages/core/dist/ServiceContext.js:7:1)
    at require.extensions.<computed> [as .js] (/Users/himself65/Library/Application Support/fnm/node-versions/v18.19.0/installation/lib/node_modules/ts-node/dist/index.js:851:20)
    at Object.<anonymous> (/Users/himself65/Code/LlamaIndexTS/packages/core/dist/index.js:11:22)
    at require.extensions.<computed> [as .js] (/Users/himself65/Library/Application Support/fnm/node-versions/v18.19.0/installation/lib/node_modules/ts-node/dist/index.js:851:20)
    at Object.<anonymous> (/Users/himself65/Code/LlamaIndexTS/examples/ollama.ts:10:22)
    at m._compile (/Users/himself65/Library/Application Support/fnm/node-versions/v18.19.0/installation/lib/node_modules/ts-node/dist/index.js:857:29)
    at require.extensions.<computed> [as .ts] (/Users/himself65/Library/Application Support/fnm/node-versions/v18.19.0/installation/lib/node_modules/ts-node/dist/index.js:859:16)
    at phase4 (/Users/himself65/Library/Application Support/fnm/node-versions/v18.19.0/installation/lib/node_modules/ts-node/dist/bin.js:466:20)
    at bootstrap (/Users/himself65/Library/Application Support/fnm/node-versions/v18.19.0/installation/lib/node_modules/ts-node/dist/bin.js:54:12)
    at main (/Users/himself65/Library/Application Support/fnm/node-versions/v18.19.0/installation/lib/node_modules/ts-node/dist/bin.js:33:12)
    at Object.<anonymous> (/Users/himself65/Library/Application Support/fnm/node-versions/v18.19.0/installation/lib/node_modules/ts-node/dist/bin.js:579:5) {
  code: 'ERR_REQUIRE_ESM'
@JonoLF
Copy link

JonoLF commented Feb 19, 2024

try either changing your file extension to .cjs to use the 'require' syntax, or define your project as a 'module' in your package.json, and then rather use the ES 'import' syntax. That's what worked for me.

@saul-jb
Copy link
Collaborator

saul-jb commented Mar 14, 2024

You can use it in a CommonJS project using dynamic import:

const { Ollama } = await import('ollama')

Or alternatively change your package system to ESM (set "type": "module" in package.json)`

import { Ollama } from 'ollama'

@BruceMacD
Copy link
Collaborator

This should work now in the most recent release, v0.5.0. Thanks to all the contributors.

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

4 participants