lmstudio-ai / lmstudio.js

LM Studio TypeScript SDK (pre-release public alpha)
https://lmstudio.ai/docs/sdk
Apache License 2.0
444 stars 74 forks source link

Named export 'LMStudioClient' not found #8

Open Trippnology opened 5 months ago

Trippnology commented 5 months ago
import { LMStudioClient } from '@lmstudio/sdk';

When I import the SDK like this, I get the following error:

import { LMStudioClient } from '@lmstudio/sdk';
         ^^^^^^^^^^^^^^
SyntaxError: Named export 'LMStudioClient' not found. The requested module '@lmstudio/sdk' is a CommonJS module, which may not support all module.exports as named exports. CommonJS modules can always be imported via the default export, for example using:

import pkg from '@lmstudio/sdk';
const { LMStudioClient } = pkg;

    at ModuleJob._instantiate (node:internal/modules/esm/module_job:132:21)
    at async ModuleJob.run (node:internal/modules/esm/module_job:214:5)
    at async ModuleLoader.import (node:internal/modules/esm/loader:329:24)
    at async loadESM (node:internal/process/esm_loader:28:7)
    at async handleMainPromise (node:internal/modules/run_main:113:12)

Adding /index.mjs does work though:

import { LMStudioClient } from '@lmstudio/sdk/index.mjs';
yagil commented 5 months ago

Please try again with 0.2.22 from the homepage: https://lmstudio.ai

ryan-the-crayon commented 5 months ago

Thanks for the report. We are still investigating how to add automatic esm support. For now, please use the 'index.mjs' entry point (as you have discovered).

import { LMStudioClient } from '@lmstudio/sdk/index.mjs';
Trippnology commented 5 months ago

No problem. As per the error message, this also works:

import SDK from '@lmstudio/sdk';
const { LMStudioClient } = SDK;
Trippnology commented 3 months ago

This may help with offering both CJS and ESM options: Create npm package with CommonJS and ESM support in TypeScript