tursodatabase / tursodatabase/libsql-client-ts
"Runtime.ImportModuleError: Error: Cannot find module '@libsql/linux-x64-gnu" when bundling with esbuild for aws lambda
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 576
- Forks
- 69
- PR merge metrics
- No merged PRs in 30d
Description
I was switching my database from planetscale to turso but I'm getting the following error
{
"errorType": "Runtime.ImportModuleError",
"errorMessage": "Error: Cannot find module '@libsql/linux-x64-gnu'\nRequire stack:\n- /var/task/index.js\n- /var/runtime/index.mjs",
"trace": [
"Runtime.ImportModuleError: Error: Cannot find module '@libsql/linux-x64-gnu'",
"Require stack:",
"- /var/task/index.js",
"- /var/runtime/index.mjs",
" at _loadUserApp (file:///var/runtime/index.mjs:1061:17)",
" at async UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:1093:21)",
" at async start (file:///var/runtime/index.mjs:1256:23)",
" at async file:///var/runtime/index.mjs:1262:1"
]
}
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
import { drizzle } from 'drizzle-orm/libsql';
import { createClient } from '@libsql/client';
const client = createClient({ url: 'DATABASE_URL', authToken: 'DATABASE_AUTH_TOKEN' });
const db = drizzle(client);
export const handler = async (event) => {
console.log('event', event);
}
the aws cdk code to deploy the function:
import {Construct} from 'constructs';
import {NodejsFunction} from 'aws-cdk-lib/aws-lambda-nodejs';
import {Architecture, Runtime} from 'aws-cdk-lib/aws-lambda';
export class SendUserToDynamo extends Construct {
function: NodejsFunction;
constructor(scope: Construct, id: string) {
super(scope, id);
// lambda function that triggers on aws lambda user created event
this.function = new NodejsFunction(this, 'sendUserToDynamo', {
entry: __dirname + '/nodejs/index.ts',
handler: 'handler',
architecture: Architecture.X86_64,
runtime: Runtime.NODEJS_18_X,
});
}
}
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with /nodejs/index.ts and the AWS CDK NodejsFunction configuration, then reproduce the deployment using esbuild and compare it with the Dockerfile build that works. Trace how the deployed bundle handles @libsql/linux-x64-gnu; done means the AWS Lambda deployment loads without Runtime.ImportModuleError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, typescript
- Domain
- build-system, cloud
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 50/100