mistralai / client-js

JS Client library for Mistral AI platform
Apache License 2.0
178 stars 45 forks source link

getting err @mistralai/mistralai v 0.1.3 doesn't support require way of importing library. i want to know the version of library which support it. #59

Open Devmindtk opened 5 months ago

Devmindtk commented 5 months ago

Error [ERR_REQUIRE_ESM]: require() of ES Module node_modules\@mistralai\mistralai\src\client.js not supported. Instead change the require of client.js to a dynamic import() which is available in all CommonJS modules.

nico-crest commented 5 months ago

Reproductible error here. const mistralai_1 = require("@mistralai/mistralai"); ^ Error [ERR_REQUIRE_ESM]: require() of ES Module node_modules/@mistralai/mistralai/src/client.js from dist/app.service.js not supported. Instead change the require of client.js in cnc-scraping/dist/app.service.js to a dynamic import() which is available in all CommonJS modules. Should we roll back to prior version ?

Devmindtk commented 5 months ago

what do you mean by dynamic import?

popmatik commented 5 months ago

Also seeing this issue. Any resolution in the pipeline please?

nbonamy commented 4 months ago

Seeing the same in an Electron app using vite.

zognotadog commented 4 months ago

Also seeing this issue when importing in typescript:

import  MistralClient from '@mistralai/mistralai';

const apiKey = process.env.MISTRAL_API_KEY;

const client = new MistralClient(apiKey);
masad08 commented 4 months ago

same issue. any luck on why/fix?

kndpt commented 4 months ago

Same issue

Bogatinovski commented 4 months ago

We have identical error when trying to import in a typescript project. Any workaround?

nbonamy commented 4 months ago

We have identical error when trying to import in a typescript project. Any workaround?

For now I just copied index.js in my project renamed it and imported it. Works for me.

ptesny commented 4 months ago

@Devmindtk , you can find in this blogpost Mistral gagnant. Mistral AI and SAP Kyma serverless.) a fully working solution of combining mistralai into a CJS module.

PS. Full recipe: mistral gagnant

ptesny commented 4 months ago

Reproductible error here. const mistralai_1 = require("@mistralai/mistralai"); ^ Error [ERR_REQUIRE_ESM]: require() of ES Module node_modules/@mistralai/mistralai/src/client.js from dist/app.service.js not supported. Instead change the require of client.js in cnc-scraping/dist/app.service.js to a dynamic import() which is available in all CommonJS modules. Should we roll back to prior version ?

@nico-crest , to address the reported error

please refer to my previous comment

Robouste commented 3 months ago

We have identical error when trying to import in a typescript project. Any workaround?

For now I just copied index.js in my project renamed it and imported it. Works for me.

What index.js are you talking about? Can you provide more guidance?

ptesny commented 3 months ago

@Robouste I have already provide a solution in this thread

Robouste commented 3 months ago

@ptesny I know, I went through it but I don't see how to implement it with nestjs as I don't really understand it to be honest :)

In the end I went the old fashion way and call their API directly using axios

nbonamy commented 3 months ago

We have identical error when trying to import in a typescript project. Any workaround?

For now I just copied index.js in my project renamed it and imported it. Works for me.

What index.js are you talking about? Can you provide more guidance?

src/client.js