Question: How to import in node.js/express server
zzzej opened this issue · 1 comments
zzzej commented
How can I import the js driver in node using require
? Thanks!
Edit:
This:
const { Client } = require("@planetscale/database");
Results in this:
Failed to load function definition from source: FirebaseError: Failed to load function definition from source: Failed to generate manifest from function source: Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/raphael/code/test/node_modules/@planetscale/database/dist/index.js from /Users/raphael/code/test/https/api.js not supported. Instead change the require of index.js in /Users/raphael/code/test/https/api.js to a dynamic import() which is available in all CommonJS modules
dgraham commented
The error message suggests using a dynamic import, which works for me like this.
const { Client } = await import('@planetscale/database');
const client = new Client(config);
const conn = client.connection();
const results = await conn.execute('select 1 from dual');