-
Notifications
You must be signed in to change notification settings - Fork 742
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
Module not found: Can't resolve 'perf_hooks' & 'module' #127
Comments
Here are some reproductions in Stackblitz: |
Solved adding the following to package.json
https://bobbyhadz.com/blog/module-not-found-cant-resolve-fs |
@GiustiRo unfortunately your solution is not working for me. Tried react, expo and vanilla webpack |
I was able to make it work changing webpack.config.js const path = require("path");
module.exports = {
entry: "./index.js",
output: {
path: path.resolve(__dirname, "dist"),
filename: "Q.js",
library: "Q",
libraryTarget: "var",
},
mode: "production",
resolve: {
fallback: {
fs: false,
path: false,
os: false,
perf_hooks: false,
}
}
}; |
cc @CharlieFRuan @sudeepag . Maybe we should include some of these comments in the webllm documents. |
I think that the real fix should be not use perf_hooks in TVMjs or generate two versions, one node and one for the browser. |
We can indeed remove the
Change these two if branches as direct throw Error stating that we are in nodejs env and as of now these compact features are not enabled. They should be fine since the two features are not used in local nodejs testing. I am not too sure about the emscripten generated polyfill however, since the modules like fs, path, os, are part of emscripten polyfill and likely it is harder to remove those. @DavidGOrtega if you can try and manually get rid of the perf_hooks and ws only and see if it works. If so, maybe we could try to proceed with the motion |
I think its just suffices checking if we are in nodejs, let me try it |
Replace `import require$$3 from 'perf_hooks';` with `const require$$3 = "MLC_DUMMY_REQUIRE_VAR"` in `index.js`. We use a dummy string because we should not reach to [this branch in tvmjs](https://github.com/apache/tvm/blob/a5862a5c696a3237f644f31bc312aae303213f3f/web/src/compact.ts#L29) which is for nodejs. This should address #258 and #127
Thanks for all the discussion and contribution. This should be addressed in npm 0.2.36. The following code snippet in https://jsfiddle.net/ should work with no setups: // See https://www.npmjs.com/package/@mlc-ai/web-llm documentation.
import * as webllm from 'https://esm.run/@mlc-ai/web-llm';
async function main() {
const initProgressCallback = (report) => {
console.log(report.text);
};
const selectedModel = "TinyLlama-1.1B-Chat-v0.4-q4f16_1-1k";
const engine = await webllm.CreateEngine(
selectedModel,
{
initProgressCallback: initProgressCallback
}
);
const reply0 = await engine.chat.completions.create({
messages: [{
"role": "user",
"content": "Tell me about Pittsburgh."
}]
});
console.log(reply0);
console.log(await engine.runtimeStatsText());
}
main(); |
Hi MLC team,
I've cloned and run your examples locally and they are working OK!
However, when I'm using your npm package inside a TS framework (Angular for instance), this error is showing up..
Error: Module not found: Error: Can't resolve 'perf_hooks'
Error: Module not found: Error: Can't resolve 'module'
What I've tried:
-Giving TS path aliasses.
-Updating your index.js file to remove this imports (not getting why, but the error persists.)
-Using different Builders (angular-devkit / custom-webpack)
-Installing @types/node devDependency as the perf_hook is used by node.
Do you know why this happens? It's a conflict because you've built in on top of parcel or rollup?..
Steps to reproduce:
Create a blank Angular project, install the library, import it and try to use it.
Thank you!
The text was updated successfully, but these errors were encountered: