fix: use @libsql/client/http subpath to avoid native module deps
The main @libsql/client entry point pulls in the native libsql module and isomorphic-ws/isomorphic-fetch, which webpack cannot parse in EdgeOne builds. Using the http subpath provides a pure HTTP client that works in edge/serverless environments without native dependencies. Also add libsql, @libsql/isomorphic-fetch, @libsql/isomorphic-ws to the edge build alias list in next.config.js as a safety net.
This commit is contained in:
@@ -104,6 +104,9 @@ const createNextConfig = (phase) => {
|
|||||||
'redis',
|
'redis',
|
||||||
'@vercel/postgres',
|
'@vercel/postgres',
|
||||||
'pg',
|
'pg',
|
||||||
|
'libsql',
|
||||||
|
'@libsql/isomorphic-fetch',
|
||||||
|
'@libsql/isomorphic-ws',
|
||||||
].map((pkg) => [
|
].map((pkg) => [
|
||||||
pkg,
|
pkg,
|
||||||
path.resolve(
|
path.resolve(
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
* 3. 运行:node scripts/init-turso.js
|
* 3. 运行:node scripts/init-turso.js
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const { createClient } = require('@libsql/client');
|
const { createClient } = require('@libsql/client/http');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const crypto = require('crypto');
|
const crypto = require('crypto');
|
||||||
|
|||||||
@@ -18,9 +18,12 @@ import { DatabaseAdapter, D1PreparedStatement, D1Result } from './d1-adapter';
|
|||||||
*
|
*
|
||||||
* 使用 require 而非 import,避免 webpack 在 EdgeOne 构建中
|
* 使用 require 而非 import,避免 webpack 在 EdgeOne 构建中
|
||||||
* 因条件导出 (edge-light) 错误解析 ESM 模块
|
* 因条件导出 (edge-light) 错误解析 ESM 模块
|
||||||
|
*
|
||||||
|
* 使用 @libsql/client/http 子路径而非主入口,避免拉入原生 libsql
|
||||||
|
* 模块和 isomorphic-ws/isomorphic-fetch 等不兼容边缘环境的依赖
|
||||||
*/
|
*/
|
||||||
function getLibsqlClient(): any {
|
function getLibsqlClient(): any {
|
||||||
const mod = require('@libsql/client');
|
const mod = require('@libsql/client/http');
|
||||||
return mod.createClient || mod.default?.createClient;
|
return mod.createClient || mod.default?.createClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user