huggingface / chat-ui

Open source codebase powering the HuggingChat app
https://huggingface.co/chat
Apache License 2.0
6.73k stars 939 forks source link

Warning: To load an ES module in Azure environment #1308

Open pronitagrawalvera opened 3 days ago

pronitagrawalvera commented 3 days ago

Hi Team,

We are currently facing issues deploying our Chat UI solution in Azure Web App. The error encountered in the console log is as follows:

npm http fetch GET 200 https://registry.npmjs.org/npm 141ms
(node:124) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
/home/site/wwwroot/node_modules/.bin/vite:2
import { performance } from 'node:perf_hooks'
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at internalCompileFunction (node:internal/vm:77:18)
    at wrapSafe (node:internal/modules/cjs/loader:1288:20)
    at Module._compile (node:internal/modules/cjs/loader:1340:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
    at Module.load (node:internal/modules/cjs/loader:1207:32)
    at Module._load (node:internal/modules/cjs/loader:1023:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:135:12)
    at node:internal/main/run_main_module:28:49

Node.js v20.11.1
npm notice 
npm notice New minor version of npm available! 10.5.0 -> 10.8.1
npm notice Changelog: https://github.com/npm/cli/releases/tag/v10.8.1
npm notice Run npm install -g npm@10.8.1 to update!
npm notice 

It appears to be a Node.js issue, and I believe there might be an error in my package.json configuration. I have tried using both Node.js 18 and 20 without success.

Could you please provide me with the correct configuration for package.json to resolve this issue?

pronitagrawalvera commented 3 days ago

HI @nsarrazin

Do you know the root cause for this issue.

nsarrazin commented 2 days ago

Not sure what would cause this, we use node 20 in our docker image.

If possible try to use the docker image we provide, that should work since we use it in prod for HuggingChat.

pronitagrawalvera commented 2 days ago

Thanks @nsarrazin but with the docker image you provide, I am getting new error on npm run build command,

npm run build
npm info using npm@10.5.0
npm info using node@v20.11.1

> chat-ui@0.9.1 build
> vite build

vite v4.5.3 building SSR bundle for production...
"BaseClient" and "TokenSet" are imported from external module "openid-client" but never used in "src/lib/server/auth.ts".
"Readable" is imported from external module "node:stream" but never used in "src/lib/server/endpoints/cohere/endpointCohere.ts".
✓ 366 modules transformed.

node:internal/event_target:1100
  process.nextTick(() => { throw err; });
                           ^
SyntaxError [Error]: JSON5: invalid character 'u' at 1:1
    at syntaxError (/home/site/wwwroot/node_modules/json5/lib/parse.js:1110:17)
    at invalidChar (/home/site/wwwroot/node_modules/json5/lib/parse.js:1055:12)
    at Object.value (/home/site/wwwroot/node_modules/json5/lib/parse.js:309:15)
    at lex (/home/site/wwwroot/node_modules/json5/lib/parse.js:100:42)
    at Object.parse (/home/site/wwwroot/node_modules/json5/lib/parse.js:25:17)
    at file:///home/site/wwwroot/.svelte-kit/output/server/chunks/auth.js:27:16
    at ModuleJob.run (node:internal/modules/esm/module_job:218:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:329:24)
    at async analyse (file:///home/site/wwwroot/node_modules/@sveltejs/kit/src/core/postbuild/analyse.js:60:16)
    at async MessagePort.<anonymous> (file:///home/site/wwwroot/node_modules/@sveltejs/kit/src/utils/fork.js:22:16)
Emitted 'error' event on Worker instance at:
    at [kOnErrorMessage] (node:internal/worker:326:10)
    at [kOnMessage] (node:internal/worker:337:37)
    at MessagePort.<anonymous> (node:internal/worker:232:57)
    at [nodejs.internal.kHybridDispatch] (node:internal/event_target:826:20)
    at exports.emitMessage (node:internal/per_context/messageport:23:28)
    at MessagePort.callbackTrampoline (node:internal/async_hooks:130:17) {
  lineNumber: 1,
  columnNumber: 1
}

Node.js v20.11.1