OvidijusParsiunas / deep-chat

Fully customizable AI chatbot component for your website
https://deepchat.dev
MIT License
1.27k stars 175 forks source link

Web Model SSR NextJs/SvelteKit #93

Closed OvidijusParsiunas closed 5 months ago

OvidijusParsiunas commented 5 months ago

When using the webModel property and attempting to add the deep-chat-web-llm module, the console displays the following error:

unhandledRejection: Error [ReferenceError]: require is not defined in ES module scope, you can use import instead
This file is being treated as an ES module because it has a '.js' file extension and '/Users/ovidijusparsiunas/Desktop/ai-chat/example-servers/nextjs/node_modules/deep-chat-web-llm/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
OvidijusParsiunas commented 5 months ago

This can be fixed by importing the module dynamically instead using the following syntax:

if (typeof window !== 'undefined') {
  import('deep-chat-web-llm').then((module) => {
    window.webLLM = module;
  });
}