GeezerVison is showing github.com — TypeError: Cannot read properties of undefined (reading '0') using client.openSession(); · Issue #264 · databricks/databricks-sql-nodejs
TypeError: Cannot read properties of undefined (reading '0') using client.openSession(); #264DescriptionPreviously working code causing a TypeError: Cannot read properties of undefined (reading '0'). This code is from the following example: https://github.com/databricks/databricks-sql-nodejs/blob/HEAD/examples/usage.js
const { DBSQLClient } = require('@databricks/sql');
import { DBSQLLogger, LogLevel } from '@databricks/sql';
import { NextResponse } from "next/server";
export async function POST(){
const logger = new DBSQLLogger({ filepath: 'log.txt', level: LogLevel.debug });
const client = new DBSQLClient({ logger: logger });
console.log("CREATED CLIENT");
client
.connect({
host: process.env.DATABRICKS_SERVER_HOSTNAME,
path: process.env.DATABRICKS_HTTP_PATH,
token: process.env.DATABRICKS_TOKEN,
})
.then(async (client: { openSession: () => any; close: () => any; }) => {
const session = await client.openSession();
console.log("SESSION CREATED");
const queryOperation = await session.executeStatement('SELECT "Hello, World!"');
const result = await queryOperation.fetchAll();
await queryOperation.close();
console.table(result);
await session.close();
await client.close();
return NextResponse.json(result);
})
.catch((error: any) => {
console.log(error);
if (error instanceof Error) {
console.error("Error executing query: ", error);
return NextResponse.json(
{ error: "Failed to execute query: ", details: error.message },
{ status: 500 }
);
}
});
}
Console output:
{"level":"info","message":"Created DBSQLClient"}
CREATED CLIENT
TypeError: Cannot read properties of undefined (reading '0')
at isInsideNodeModules (node:internal/util:508:17)
at showFlaggedDeprecation (node:buffer:178:8)
at new Buffer (node:buffer:266:3)
at new module.exports (webpack-internal:///(rsc)/./node_modules/node-int64/Int64.js:65:34)
at DBSQLClient.eval (webpack-internal:///(rsc)/./node_modules/@databricks/sql/dist/DBSQLClient.js:197:111)
at Generator.next (<anonymous>)
at eval (webpack-internal:///(rsc)/./node_modules/@databricks/sql/dist/DBSQLClient.js:31:71)
at new Promise (<anonymous>)
at __awaiter (webpack-internal:///(rsc)/./node_modules/@databricks/sql/dist/DBSQLClient.js:27:12)
at DBSQLClient.openSession (webpack-internal:///(rsc)/./node_modules/@databricks/sql/dist/DBSQLClient.js:196:16)
at eval (webpack-internal:///(rsc)/./app/api/databricks-test/route.ts:25:38)
Error executing query: TypeError: Cannot read properties of undefined (reading '0')
at isInsideNodeModules (node:internal/util:508:17)
at showFlaggedDeprecation (node:buffer:178:8)
at new Buffer (node:buffer:266:3)
at new module.exports (webpack-internal:///(rsc)/./node_modules/node-int64/Int64.js:65:34)
at DBSQLClient.eval (webpack-internal:///(rsc)/./node_modules/@databricks/sql/dist/DBSQLClient.js:197:111)
at Generator.next (<anonymous>)
at eval (webpack-internal:///(rsc)/./node_modules/@databricks/sql/dist/DBSQLClient.js:31:71)
at new Promise (<anonymous>)
at __awaiter (webpack-internal:///(rsc)/./node_modules/@databricks/sql/dist/DBSQLClient.js:27:12)
at DBSQLClient.openSession (webpack-internal:///(rsc)/./node_modules/@databricks/sql/dist/DBSQLClient.js:196:16)
at eval (webpack-internal:///(rsc)/./app/api/databricks-test/route.ts:25:38)
⨯ Error: No response is returned from route handler '/home/slloyd/database_ai_assistant/app/api/databricks-test/route.ts'. Ensure you return a `Response` or a `NextResponse` in all branches of your handler.
at /home/slloyd/database_ai_assistant/node_modules/next/dist/compiled/next-server/app-route.runtime.dev.js:6:53611
at async e_.execute (/home/slloyd/database_ai_assistant/node_modules/next/dist/compiled/next-server/app-route.runtime.dev.js:6:44747)
at async e_.handle (/home/slloyd/database_ai_assistant/node_modules/next/dist/compiled/next-server/app-route.runtime.dev.js:6:54700)
at async doRender (/home/slloyd/database_ai_assistant/node_modules/next/dist/server/base-server.js:1377:42)
at async cacheEntry.responseCache.get.routeKind (/home/slloyd/database_ai_assistant/node_modules/next/dist/server/base-server.js:1599:28)
POST /api/databricks-test 500 in 133ms
The only change made was adding:
webpack: (config) => {
config.resolve.alias.lz4 = false;
return config;
},
to my next.config.js to prevent the following error:
Module not found: Can't resolve '../build/Release/xxhash'```
Activitykravets-levko commented on Aug 14, 2024 Hi @scott16lloyd! Which Node version you use? Seems that your error is caused by this change to Node's utils module: nodejs/node#52147 Also, it would help if you share your devloop setup. If you're using Webpack, it may polyfill some native Nodejs APIs and sometimes break things kravets-levko commented on Aug 14, 2024 Also, seems somebody already stumbled at similar error, but the code wasn't properly fixed: nodejs/node#53089 scott16lloyd commented on Aug 15, 2024 Thank you for your reply @kravets-levko , I was running LTS version 20.16.0 so I tried 21.7.3 where I got:
Error: Module did not self-register: '/home/slloyd/database_ai_assistant/node_modules/lz4/build/Release/xxhash.node'. and node:419153) [DEP0040] DeprecationWarning: The punycode module is deprecated. Please use a userland alternative instead.
so I tried the current version 22.6.0 which did run my code but there is 2 deprecation warnings:
(node:420067) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(node:420067) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead
punycode warning seems to be an issue with eslint:
npm ls punycode
and the Buffer() issue seems to link to lz4:
I assume this is out of your control and we must wait for an update from eslint and lz4 but is it possible to create a version that will support an LTS version of Node? Or warn users that the current version must be used? kravets-levko commented on Aug 15, 2024 @scott16lloyd Thank you for those details! I need to check if we can do anything on our side. I think upgrading eslint should be painless, and if it doesn't depend on punycode anymore - I'll do that. For Buffer warnings - new Buffer(...) is also widely used in node-int64 which is quite old and doesn't receive updates, but thrift heavily depends on it. While those are just warnings and don't disrupt your workflow - you can ignore them for now. I'll get back to you when I have any updates edgarlcs commented on Aug 27, 2024 I am getting the same error on newer Node JS versions (20.16.0) But the error goes away on an earlier version (18.18.2) manuel-barreiro commented on Dec 16, 2024 Having the same problem using Next JS 14. Any solution? alangabrielbs commented on Apr 9, 2025 Has anyone managed to solve this? alangabrielbs commented on Jul 8, 2025
Having the same problem using Next JS 14. Any solution?
Did you find any solution to use in nextjs? vuanhphung commented on Oct 29, 2026 I retested this with the latest release (@databricks/[email protected]) in a Next.js 14 app router route, using the code from this issue.
The TypeError: Cannot read properties of undefined (reading '0') comes from a Node.js bug in the new Buffer() deprecation warning. It was fixed in Node 20.17.0 and 22.5.0, which is why it appeared on 20.16.0 but not on 22.6.0. On Node 24, the same route runs without the error.
The lz4 build error is also gone, because the driver now uses lz4-napi, which ships prebuilt binaries. The driver does include native modules, so don't let webpack bundle it. Add it to serverComponentsExternalPackages (Next 14) or serverExternalPackages (Next 15+):
// next.config.js (Next 14)
module.exports = {
experimental: { serverComponentsExternalPackages: ['@databricks/sql'] },
};
With that setting, the route returned the query result with no errors or warnings.
Closing this. If you still see it on a current Node version with the latest driver, please open a new issue with your Node and Next.js versions.
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|