Closed arthurwolf closed 10 months ago
It's failing because you're using Imports outside of a node module. Nothing to do with this project. The node error message describes a fix - Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
Therefore, rename your original file that uses Imports from .js to .mjs and run node filename.mjs
and it will work
@arthurwolf node-llama-cpp
is an ES module, so you can only import
it and cannot use it with require
, and to do so your project has to be an ES module as well.
Just like the error you've got says:
(node:2540491) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
You should add "type": "module"
to the package.json
of your project, and then the code will work for you.
I'll add a section in the getting started guide to explain this better.
:tada: This issue has been resolved in version 2.7.4 :tada:
The release is available on:
Your semantic-release bot :package::rocket:
Issue description
Following instructions as-is just doesn' t work.
Expected Behavior
Working.
Actual Behavior
Not working.
Steps to reproduce
I follow the exact instructions at https://www.npmjs.com/package/node-llama-cpp (npm install and copy/paste code into .js file)
I try running (only changing the line with the .gguf file to using a file on my harddrive) it I get:
Google recommends I change to:
So I do that (am I wrong or is it impossible for the example given in the README to work...?), and I get:
So I put the awaits inside an async:
now I get:
At that point I just give up...
(Note this is after nearly an hour trying to get this module to work with ts-node, and utterly failing, despite trying DOZENS of things from Google and ChatGPT... I use thousands of modules from npm in ts projects, this is the first time I get this much trouble... whfich is why I failed back to trying to run it with node (instead of ts-node) to simplify the issue, and as you can see above, even that fails...)
I'm at a loss...
Any help welcome.
My Environment
Latest Ubuntu, Node 20.5.1
Additional Context
No response
Relevant Features Used
Are you willing to resolve this issue by submitting a Pull Request?
Yes, I have the time, and I know how to start.