libSQL Bundling Error with Expo Router v3 API Routes
Hello everyone, I'm currently in the process of building an Expo app utilizing the Expo Router v3 API routes. Previously, I had been using Planetscale without any issues. However, upon attempting to migrate to Turso, I've encountered a bundling error:
Metro error: Unable to resolve module ./.targets from /Users/fefranco/code/libsql-expo/node_modules/libsql/index.js:
None of these files exist:
* node_modules/libsql/.targets(.web.ts|.ts|.web.tsx|.tsx|.web.js|.js|.web.jsx|.jsx|.web.json|.json|.web.cjs|.cjs|.web.mjs|.mjs|.web.scss|.scss|.web.sass|.sass|.web.css|.css)
* node_modules/libsql/.targets/index(.web.ts|.ts|.web.tsx|.tsx|.web.js|.js|.web.jsx|.jsx|.web.json|.json|.web.cjs|.cjs|.web.mjs|.mjs|.web.scss|.scss|.web.sass|.sass|.web.css|.css)
6 | // Static requires for bundlers.
7 | if (0) {
> 8 | require("./.targets");
| ^
9 | }
10 |
11 | let target = currentTarget();
Call Stack
Object.requireFileContentsWithMetro (node_modules/@expo/cli/src/start/server/getStaticRenderFunctions.ts:190:13)
processTicksAndRejections (node:internal/process/task_queues)
bundleAsync (node_modules/@expo/cli/src/start/server/metro/bundleApiRoutes.ts:39:26)
getApiRoute (node_modules/@expo/cli/src/start/server/metro/createServerRouteMiddleware.ts:138:36)
handler (node_modules/@expo/server/src/index.ts:178:20)
<unknown> (node_modules/@expo/server/src/vendor/http.ts:36:24)
TypeError: Cannot read properties of null (reading 'GET')
at handler (/Users/fefranco/code/libsql-expo/node_modules/@expo/server/src/index.ts:184:32)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at /Users/fefranco/code/libsql-expo/node_modules/@expo/server/src/vendor/http.ts:36:24
Unable to resolve "./.targets" from "node_modules/libsql/index.js"
I've created a minimal reproduction of the issue in CodeSandbox
I encountered the same problem using Turso, Android Bundling failed 12919ms C:\Users\ableez\Documents\Repos\askerisk\node_modules\expo-router\entry.js (3444 modules) Unable to resolve "@libsql/core/config" from "node_modules@libsql\client\lib-cjs\node.js"
I encountered the same problem using Turso, Android Bundling failed 12919ms C:\Users\ableez\Documents\Repos\askerisk\node_modules\expo-router\entry.js (3444 modules) Unable to resolve "@libsql/core/config" from "node_modules@libsql\client\lib-cjs\node.js"
I am experiencing the same issue! Any libsql-js dev can solve this? We can't connect Turso databases with an expo-react native app!
Expo is doing its static analysis on the libsql file.
if (0) {
require("./.targets");
}
This is suppose to only load when it's in "dev" mode:
if (process.env.LIBSQL_JS_DEV) {
return load(__dirname)
}
Turso can add a try/catch, or you can create a temporary .targets file in node_modules/libsql/.targets
If that doesn't work, try monkey patching that library.
Any fixes planned @penberg ?