I followed Get Started to use javascript sdk but i’m getting error during import of library.
I’m using 0.8.31 rockset/client and my function lambda is built with ESM format.
This is the error I received:
Error: (0 , import_client.default) is not a function
import rockset from "@rockset/client";
import { Config } from 'sst/node/config';
const rockset_client = rockset(Config.ROCKSET_APIKEY, 'https://api.use1a1.rockset.com');
Is rockset compatible with ESM or is there some other issue?
The issue here is with import { Config } from 'sst/node/config'; not with the usage of the client. Easiest way to test this is to remove the import and just insert any other string as the key and it should at least run. If that doesn’t work, then it’s something with the environment since that syntax is correct. Can you test it and post here?
Also, I noticed in your screenshot you are missing ‘const rs = rockset.default(“asdf”);’ . Adding this will not fix the issue, but be sure to include it since missing it may cause problems down the line.
I’m using SST , a superset of AWS CDK (you can mix CDK constructor and SST constructor).
When I make a lambda I use the constructor Function Function | SST.
I just specify an handler (a simple javascript function) and it is built with esbuild and deployed.
In this moment I’m making calls with axios to works with Rockset until understand how works with sdk.
Thank you for your detailed response! We were able to bundle a package with the client as a dependency using esbuild without any issues. Can you verify that your code works when just using esbuild without sst. If it does, then we know it’s a problem with SST + the client.
file:///Users/gmarino/Workspace/rockset-client-nodejs-example/out.mjs:12
throw new Error('Dynamic require of "' + x + '" is not supported');
^
Error: Dynamic require of "url" is not supported
at file:///Users/gmarino/Workspace/rockset-client-nodejs-example/out.mjs:12:9
at node_modules/.pnpm/@rockset+client@0.8.31/node_modules/@rockset/client/dist/codegen/api.js (file:///Users/gmarino/Workspace/rockset-client-nodejs-example/out.mjs:3111:15)
at __require2 (file:///Users/gmarino/Workspace/rockset-client-nodejs-example/out.mjs:15:50)
at node_modules/.pnpm/@rockset+client@0.8.31/node_modules/@rockset/client/dist/index.js (file:///Users/gmarino/Workspace/rockset-client-nodejs-example/out.mjs:9648:15)
at __require2 (file:///Users/gmarino/Workspace/rockset-client-nodejs-example/out.mjs:15:50)
at file:///Users/gmarino/Workspace/rockset-client-nodejs-example/out.mjs:9753:29
at ModuleJob.run (node:internal/modules/esm/module_job:193:25)
at async Promise.all (index 0)
at async ESMLoader.import (node:internal/modules/esm/loader:526:24)
at async loadESM (node:internal/process/esm_loader:91:5)