asg017 / sqlite-vec

A vector search SQLite extension that runs anywhere!
Apache License 2.0
4.26k stars 135 forks source link

CommonJS syntax error #79

Closed achrafash closed 3 months ago

achrafash commented 3 months ago

Using the npm package sqlite-vec in a commonjs project I get:

/Users/achraf/test-sqlite-vec/node_modules/sqlite-vec/index.cjs:42
    fileURLToPath(new URL(".", import.meta.url)),
                                      ^^^^

SyntaxError: Cannot use 'import.meta' outside a module
    at internalCompileFunction (node:internal/vm:73:18)
    at wrapSafe (node:internal/modules/cjs/loader:1178:20)
    at Module._compile (node:internal/modules/cjs/loader:1220:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
    at Module.load (node:internal/modules/cjs/loader:1119:32)
    at Module._load (node:internal/modules/cjs/loader:960:12)
    at Module.require (node:internal/modules/cjs/loader:1143:19)
    at require (node:internal/modules/cjs/helpers:121:18)
    at Object.<anonymous> (/Users/achraf/test-sqlite-vec/index.js:2:19)
    at Module._compile (node:internal/modules/cjs/loader:1256:14)

Node.js v18.17.1

I was able to fix it by making the following change in index.cjs:

// current
fileURLToPath(new URL(".", import.meta.url)),
// fix
fileURLToPath(new URL(".", `file:${__dirname}/`)),

I can’t find the source for the package so I didn’t open a PR. Thanks!

asg017 commented 3 months ago

@achrafash just published v0.1.2-alpha.4 with a fix for this - can you try it out and let me know if it works?

achrafash commented 3 months ago

again, you nailed it! thanks a lot 🙏