Skip to content

Common Js support #280

Closed Answered by giladgd
sooraj007 asked this question in Q&A
Discussion options

You must be logged in to vote

I don't plan to add support for CommonJS, as it'll make it much more complicated to maintain and develop, and ESM is the official way forward in nodejs.
I've explained it more in depth here.

If you'd like to import this library from inside of a CommonJS project without changing the project to be an ES module, you can do this:

async function myLogic() {
    const {getLlama} = await import("node-llama-cpp");

    const llama = await getLlama();
}

myLogic();

And if your tsconfig.json is configured to transpile import into require automatically, you can do this instead:

async function myLogic() {
    const nlc: typeof import("node-llama-cpp") = await Function('return import("node-llama-cpp")')(

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by giladgd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants