Comments (10)
make a high-level remark here. The emscripten generate module have some conditional blocks for nodejs (this is default behavior of emscripten) and it does not work well with some of the bundlers.
if (NODE_JS) {
require(nxxxx)
} else {
this is what is useful in ES
}
One way to address this is to write a python script that remove the block in if (NODE_JS)
, which should be fine as long as we are not running in nodejs.
if (NODE_JS) {.
throw Error("This module does not yet work on nodejs env")
} else {
job as usual
}
from web-llm.
Looking into this!
from web-llm.
Thank you @DiegoCao! Are you able to replicate this problem? Thanks for your help!
from web-llm.
I've replicated the problem, will try to fix it
from web-llm.
I've replicated the problem, will try to fix it
@DiegoCao - Any updates on this? Thanks!
from web-llm.
I was able to work around this by disabling SSR. For SvelteKit this meant adding export const ssr = false;
to src/routes/+layout.ts
.
from web-llm.
I've met the same problem. This issues need to be further investigated.
from web-llm.
i just changed the next.config.js, problem solved:
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
webpack: (config, { isServer }) => {
// Fixes npm packages that depend on `fs` module
if (!isServer) {
config.resolve.fallback = {
...config.resolve.fallback, // if you miss it, all the other options in fallback, specified
// by next.js will be dropped. Doesn't make much sense, but how it is
fs: false, // the solution
module: false,
perf_hooks: false,
};
}
return config
},
};
export default nextConfig;
from web-llm.
i just changed the next.config.js, problem solved:
/** @type {import('next').NextConfig} */ const nextConfig = { reactStrictMode: true, webpack: (config, { isServer }) => { // Fixes npm packages that depend on `fs` module if (!isServer) { config.resolve.fallback = { ...config.resolve.fallback, // if you miss it, all the other options in fallback, specified // by next.js will be dropped. Doesn't make much sense, but how it is fs: false, // the solution module: false, perf_hooks: false, }; } return config }, }; export default nextConfig;
This still doesn't work for me. In my case the export
will throw error on npm run dev
.
(node:43180) 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)
/Users/neet/code/web-llm/examples/next-simple-chat/next.config.js:22
export default nextConfig;
^^^^^^
SyntaxError: Unexpected token 'export'
at wrapSafe (node:internal/modules/cjs/loader:1389:18)
at Module._compile (node:internal/modules/cjs/loader:1425:20)
at Module._extensions..js (node:internal/modules/cjs/loader:1564:10)
at Module.load (node:internal/modules/cjs/loader:1287:32)
at Module._load (node:internal/modules/cjs/loader:1103:12)
at cjsLoader (node:internal/modules/esm/translators:318:15)
at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:258:7)
at ModuleJob.run (node:internal/modules/esm/module_job:262:25)
at async ModuleLoader.import (node:internal/modules/esm/loader:474:24)
at async loadConfig (/Users/neet/code/web-llm/examples/next-simple-chat/node_modules/next/dist/server/config.js:678:36)
And even if I add "type": "module"
to package.json
, the following error will still occur:
⨯ 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/neet/code/web-llm/examples/next-simple-chat/node_modules/@mlc-ai/web-llm/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
at file:///Users/neet/code/web-llm/examples/next-simple-chat/node_modules/@mlc-ai/web-llm/lib/index.js:4855:74
at file:///Users/neet/code/web-llm/examples/next-simple-chat/node_modules/@mlc-ai/web-llm/lib/index.js:4867:5
at file:///Users/neet/code/web-llm/examples/next-simple-chat/node_modules/@mlc-ai/web-llm/lib/index.js:4794:3
at file:///Users/neet/code/web-llm/examples/next-simple-chat/node_modules/@mlc-ai/web-llm/lib/index.js:4795:3
at file:///Users/neet/code/web-llm/examples/next-simple-chat/node_modules/@mlc-ai/web-llm/lib/index.js:5013:2
at ModuleJob.run (node:internal/modules/esm/module_job:262:25)
at async ModuleLoader.import (node:internal/modules/esm/loader:474:24) {
page: '/'
}
I believe this is a bundler issue, but somehow this issue only happens to this example but not my another Next.js project. Very weird.
from web-llm.
This error should be addressed in npm 0.2.36. For details please see #397.
from web-llm.
Related Issues (20)
- Error running the function calling example: Cannot find global function mlc.serve.BNFGrammarGetGrammarOfJSON HOT 3
- BufferSource argument is empty HOT 4
- [MLC-LLM] Uncaught (in promise) LinkError: WebAssembly.instantiate(): Import #4 "env" HOT 2
- IndexedDB cache fails like the caches HOT 6
- Create a simpler web-workers example HOT 2
- Error: Cannot find global function tvmjs.runtime.ArrayConcat HOT 3
- Do you plan to support LLaVA or video-LLaVA?
- Check failed: (!free_page_ids_.empty()) is false: The KV cache is full. No page can be allocated.
- Models output is scrambled in Safari Technology Preview, which has WebGPU support HOT 1
- Generate error, OperationError: Device lost during onSubmittedWorkDone (do not use this error for recovery - it is NOT guaranteed to happen on device loss) HOT 2
- Strange reply from Phi2-q4f32_1-1k model in running the Web-llm Chat Demo
- Cache.add() encountered a network error HOT 6
- Create a chat webapp with elegant UI on mlc.ai HOT 5
- Cannot find WebGPU on Safari (works on Arc) HOT 2
- Fetching model param super slow on Vercel HOT 1
- Engine not instantiating for WebWorker
- In the Llama-2-7b-chat-hf-q4f32_1-1k model, the number of tokens in the prefill is 36 when inputting 'hello'. HOT 2
- [Tracking] WebLLM: Frontend Compatibility Issues and CDN Delivery HOT 2
- Issue with source map in v0.2.37 when running with Vite HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from web-llm.