tursodatabase / libsql

libSQL is a fork of SQLite that is both Open Source, and Open Contributions.
https://turso.tech/libsql
MIT License
11.58k stars 288 forks source link

Turborepo, build package, nodeFetch is not a function #879

Open paulm17 opened 10 months ago

paulm17 commented 10 months ago

I'm working on an app, which will go into production testing within 14 days.

I'm running turborepo and I have drizzle / turso running in a separate workspace. Which gets built and used by an application.

When I do not build the package and the gateway in package.json is "main": "/src/index.ts",. Everything works fine.

However, when I build it to simulate production AND to get the types when I import the package. I get the following:

 TypeError: nodeFetch is not a function
     at fetch (webpack-internal:///(action-browser)/../../node_modules/.pnpm/@libsql+isomorphic-fetch@0.1.10/node_modules/@libsql/isomorphic-fetch/node.cjs:126:12)
     at #flush (webpack-internal:///(action-browser)/../../node_modules/.pnpm/@libsql+hrana-client@0.5.5/node_modules/@libsql/hrana-client/lib-cjs/http/stream.js:255:23)
     at #flushPipeline (webpack-internal:///(action-browser)/../../node_modules/.pnpm/@libsql+hrana-client@0.5.5/node_modules/@libsql/hrana-client/lib-cjs/http/stream.js:243:20)
     at #flushQueue (webpack-internal:///(action-browser)/../../node_modules/.pnpm/@libsql+hrana-client@0.5.5/node_modules/@libsql/hrana-client/lib-cjs/http/stream.js:235:32)
     at eval (webpack-internal:///(action-browser)/../../node_modules/.pnpm/@libsql+hrana-client@0.5.5/node_modules/@libsql/hrana-client/lib-cjs/http/stream.js:192:74)
     at node:internal/process/task_queues:140:7
     at AsyncResource.runInAsyncScope (node:async_hooks:203:9)
     at AsyncResource.runMicrotask (node:internal/process/task_queues:137:8)
     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
  ⨯ ../../packages/db/dist/index.cjs
 Error: Failed to read source code from /Users/paul/development/src/golfcart/packages/db/dist/index.cjs

 Caused by:
     No such file or directory (os error 2)

 Import trace for requested module:
 ../../packages/db/dist/index.cjs
 ./src/app/(auth)/signup/actions.ts

Let me know if you require a MVP to take a look.

paulm17 commented 10 months ago

After a bit of playing around. I can get around this for development purposes.

"main": "./src/index.ts",
"exports": {
    ".": {
      "types": "./dist/index.d.cts",
      "import": "./src/index.ts",
      "require": "./src/index.ts"
    }
  },

But wouldn't mind resolving this for when I decide to push this to prod for testing purposes.

Thanks!