Closed linonetwo closed 1 year ago
Get this after externalize it by
new ExternalsPlugin({
type: 'commonjs',
// use regex works.
include: /@tiddlygit\+tiddlywiki@(.+)|llama-node(.+)|@llama-node(.+)/,
// when using npm, we can use this. But with pnpm, this won't work ↓
// include: path.join(__dirname, 'node_modules', '.pnpm', '@tiddlygit', 'tiddlywiki'),
}),
new ThreadsPlugin({
target: 'electron-node-worker',
plugins: ['ExternalsPlugin'],
}),
require() of ES Module xx/Resources/node_modules/llama-node/dist/llm/llama-cpp.js from xx/Resources/app.asar.unpacked/.webpack/main/948.index.worker.js not supported.
Instead change the require of llama-cpp.js in xx/Resources/app.asar.unpacked/.webpack/main/948.index.worker.js to a dynamic import() which is available in all CommonJS modules. Error [ERR_REQUIRE_ESM]: require() of ES Module xx/Resources/node_modules/llama-node/dist/llm/llama-cpp.js from xx/Resources/app.asar.unpacked/.webpack/main/948.index.worker.js not supported.
Instead change the require of llama-cpp.js in xx/Resources/app.asar.unpacked/.webpack/main/948.index.worker.js to a dynamic import() which is available in all CommonJS modules.
This works
const { LLM } = await import('llama-node');
const { LLamaCpp } = await import('llama-node/dist/llm/llama-cpp.cjs');
with
declare module 'llama-node/dist/llm/llama-cpp.cjs' {
export { LLamaCpp } from 'llama-node/dist/llm/llama-cpp';
}
I always get #461 for a worker, I think is is due to fail to import some deps, so I use dynamic import instead for a try
And I get
importScripts is not defined
related compiled code