-
Notifications
You must be signed in to change notification settings - Fork 685
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Next example doesn't work unless source is built #140
Comments
Get it.. this is surprising, would be useful to look into the difference. I wonder if it has to do with way things are bundled |
As described in #140, for some reason the prebuilt package isn't working.
getting this error:
|
Just to confirm, you're seeing that error when using the pre built binary from npm, and not when building from source, correct? if yes, it matches my error as well |
yes. Right. Building a source is not possible. If it is required, why not just upload the binaries in a seperate repo? |
To clarify a bit See instructions to build form source here: https://github.com/mlc-ai/web-llm#build-webllm-package-from-source |
Would be helpful if you could provide more information about why building from source did not work, and if the issue was with the next integration specifically or you were not able to build from source at all. I have a working example here which works with next js, complete with a script to build from source on vercel. |
Also, I think if your problems are unrelated to the next integration and more about inability to build from source, you might want to create a new issue |
With any Next.js project, the examples/next-simple-chat project, when the pre-built Web LLM package from the NPM package registry @mlc-ai/web-llm (as of 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 '.../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. One way to fix the above ES Module and CommonJS syntax mixing is by leveraging Next.js's support for automatically transpiling dependencies from packages. With Next.js /** @type {import('next').NextConfig} */
const nextConfig = {
transpilePackages: ['@mlc-ai/web-llm'],
...
}
module.exports = nextConfig So, we could update examples/next-simple-chat/next.config.js with the above line to get rid of the above But that results in the following compiler error: - error ./node_modules/@mlc-ai/web-llm/lib/index.js
Module parse failed: Identifier 'Module' has already been declared (6895:20)
| return async function() {
| let Module = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
> var Module = typeof Module != "undefined" ? Module : {};
| var readyPromiseResolve, readyPromiseReject;
| Module["ready"] = new Promise(function(resolve, reject) {
Import trace for requested module:
./node_modules/@mlc-ai/web-llm/lib/index.js
./src/utils/chat_component.tsx Her's the diff of the pre-built The above error is likely because of the redefinition of The rollup.config.js and examples/next-simple-chat/next.config.js doesn't seem to be in sync to produce the same bundle/compiled output. If the use of CommonJS cannot be avoided in the bundle, a solution to consider is to conditionally export CommonJS for |
Hi @praveen-palanisamy, thank you so much for helping here - I did not have the NextJS expertise necessary to understand what was wrong. I was able to follow along in your explanation until the following line:
I would love to fix this, since it seems like it would fix the root of the problem. Do you have any ideas on how we can sync the two? |
Is there any progress on this issue? |
This error should be addressed in npm |
The next example only seems to work when the source is built locally, and not when it's installed from npm.
Weirdly enough, if I install the source locally and then switch to using the prebuilt npm package, it works :/
Trial 1: Using prebuilt npm package only
Trial 2: Using prebuilt npm package after locally installing web-llm
Trial 3: Building from source
I'm a bit flummoxed as to why 1 doesn't work but 2 and 3 work. Specially 2 is surprising to me.
The text was updated successfully, but these errors were encountered: