-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"Runtime.ImportModuleError: Error: Cannot find module '@libsql/linux-x64-gnu" when bundling with esbuild for aws lambda #112
Comments
Similar error happens when deploying to vercel. Any advice? Update |
same here |
0.3.3 also works |
bump |
Confirming I'm seeing this too, also switching from Planetscale to Turso. |
Ran into this too and got it working with 0.3.3. |
Having a similar issue, but I'm on Windows 11 and getting:
Works with |
I'm experiencing this on an arm lambda: tursodatabase/libsql-js#70 edit: 0.3.3 does fix this. |
I ended up using the web/HTTP client to be able to run the latest version: import { createClient } from '@libsql/client/web'; |
it does say in the docs that you should use it for vercel functions and the like. the docs could be a bit clearer here. nothing mentions what to use for lambda |
Just wanted to chime in that I also ran into this exact same issue deploying to AWS Lambda using Architect and on version The suggestion to use web worked for me. 👍 |
The same problem here using versions 0.5.x and 0.6.x with Deno Deploy with NPM comparability layer. I tried to use it with esm.sh but I didn't have any success. |
If you want to use the native client that uses the A bundler like esbuild won't be able to include the correct version (i.e. This worked for me: import { Stack, type StackProps, CfnOutput } from 'aws-cdk-lib';
import { Construct } from 'constructs';
import { Architecture, Code, LayerVersion, Runtime } from 'aws-cdk-lib/aws-lambda';
import { NodejsFunction, OutputFormat } from 'aws-cdk-lib/aws-lambda-nodejs';
export class LibsqlStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);
const libsqlLayer = new LayerVersion(this, 'LibsqlLayer', {
compatibleArchitectures: [Architecture.ARM_64],
compatibleRuntimes: [Runtime.NODEJS_20_X],
code: Code.fromAsset('./layers/libsql/nodejs', {
bundling: {
image: Runtime.NODEJS_20_X.bundlingImage,
environment: {
npm_config_cache: "/tmp/npm_cache",
npm_config_update_notifier: "false",
},
command: [
'bash',
'-xc',
[
'cd $(mktemp -d)',
'cp /asset-input/package* .',
'npm --prefix . i @libsql/client',
'cp -r node_modules /asset-output/'
].join(' && '),
]
}
}),
});
const fn = new NodejsFunction(this, 'MyFunction', {
runtime: Runtime.NODEJS_20_X,
architecture: Architecture.ARM_64,
entry: './src/index.ts',
handler: 'handler',
bundling: {
minify: true,
mainFields: ['module', 'main'],
sourceMap: true,
format: OutputFormat.ESM,
externalModules: ['@libsql/client'],
},
layers: [libsqlLayer],
});
new CfnOutput(this, 'FunctionArn', {
value: fn.functionArn,
});
}
} then in my function I use import { Logger } from "@aws-lambda-powertools/logger";
import { createClient } from "@libsql/client";
const logger = new Logger();
const db = createClient({
url: "file:/tmp/sqlite.db",
});
export const handler = async () => {
await db.execute("CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY, name TEXT)");
await db.execute({ sql: "INSERT INTO users (name) VALUES (?)", args: ["Alice"]});
const rows = await db.execute("SELECT * FROM users");
logger.info("Rows: ", {rows});
return {
statusCode: 200,
body: JSON.stringify("Hello, World!"),
};
}; which when invoked prints this: {
"level": "INFO",
"message": "Rows: ",
"sampling_rate": 0,
"service": "service_undefined",
"timestamp": "2024-06-27T18:14:43.388Z",
"xray_trace_id": "1-667dac12-2624c2867735f80f34586f58",
"rows": {
"columns": [
"id",
"name"
],
"columnTypes": [
"INTEGER",
"TEXT"
],
"rows": [
[
1,
"Alice"
]
],
"rowsAffected": 0,
"lastInsertRowid": null
}
} The advantage of using a Lambda layer like that is that you can still continue using |
I was switching my database from planetscale to turso but I'm getting the following error
I use the aws cdk to build and deploy my aws lambda function internally it uses esbuild here is a simple reproduction step
the aws lambda function code
/nodejs/index.ts
the aws cdk code to deploy the function:
Everything works when I'm using the PlanetScale driver, so the error must come from libsql and not the CDK build step. I tried using a Dockerfile without TypeScript and ESBuild, and it did work
The text was updated successfully, but these errors were encountered: