supabase-community / seed

Automatically seed your database with production-like dummy data based on your schema for local development and testing.
MIT License
469 stars 17 forks source link

TypeError: Cannot read properties of undefined (reading 'bind') #189

Closed jmgunter closed 2 months ago

jmgunter commented 3 months ago

A new installation of @snaplet/seed in my typescript project is now throwing this error when running npx tsx seed.ts

TypeError: Cannot read properties of undefined (reading 'bind')
    at Object.<anonymous> (/Users/xyz/Development/xyz/node_modules/fictional/hash.js:7:43)
    at Module._compile (node:internal/modules/cjs/loader:1376:14)
    at Object.transformer (/Users/xyz/.npm/_npx/fd45a72a545557e9/node_modules/tsx/dist/register-DxMxtvGN.cjs:2:1122)
    at Module.load (node:internal/modules/cjs/loader:1207:32)
    at Module._load (node:internal/modules/cjs/loader:1023:12)
    at Module.require (node:internal/modules/cjs/loader:1235:19)
    at require (node:internal/modules/helpers:176:18)
    at Object.<anonymous> (/Users/xyz/Development/xyz/node_modules/fictional/index.js:1:16)
    at Module._compile (node:internal/modules/cjs/loader:1376:14)
    at Object.transformer (/Users/xyz/.npm/_npx/fd45a72a545557e9/node_modules/tsx/dist/register-DxMxtvGN.cjs:2:1122)

My seed.ts file:


import { createSeedClient } from "@snaplet/seed";

require("dotenv").config({ path: "./.env.local" });

const main = async () => {
  const seed = await createSeedClient({ dryRun: true }); // Only log the queries that would be executed so we can use supabase's built in logging

// Doing some seeding here

  process.exit();
};

main();
Aietes commented 3 months ago

I'm having a similar issue with a setup that worked just fine until now:

> npx tsx seed.ts

<project>/node_modules/.pnpm/fictional@2.0.2/node_modules/fictional/hash.js:7
var generateKey = siphash.string16_to_key.bind(siphash)
                                          ^

TypeError: Cannot read properties of undefined (reading 'bind')
    at Object.<anonymous> (<project>/node_modules/.pnpm/fictional@2.0.2/node_modules/fictional/hash.js:7:43)
    at Module._compile (node:internal/modules/cjs/loader:1358:14)
    at Object.transformer (/Users/xxx/.npm/_npx/fd45a72a545557e9/node_modules/tsx/dist/register-DxMxtvGN.cjs:2:1122)
    at Module.load (node:internal/modules/cjs/loader:1208:32)
    at Module._load (node:internal/modules/cjs/loader:1024:12)
    at Module.require (node:internal/modules/cjs/loader:1233:19)
    at require (node:internal/modules/helpers:179:18)
    at Object.<anonymous> (<project>/node_modules/.pnpm/fictional@2.0.2/node_modules/fictional/index.js:1:16)
    at Module._compile (node:internal/modules/cjs/loader:1358:14)
    at Object.transformer (/Users/xxx/.npm/_npx/fd45a72a545557e9/node_modules/tsx/dist/register-DxMxtvGN.cjs:2:1122)

Node.js v20.15.1
 ELIFECYCLE  Command failed with exit code 1.

This happens on import, even if I have nothing else in seed.ts. Just import { createSeedClient } from '@snaplet/seed' causes the error.

I rolled back the snaplet version, and even the entire project, but I always get this error. I'm baffled to why?

camrun91 commented 3 months ago

I am having the same issue and it has all worked until this morning. I wonder if it has something to do with Snaplet shutting down?

josematute commented 3 months ago

Same issue here.

Aietes commented 3 months ago

Since the error comes from the fictional package, I also opened an issue over there: https://github.com/oftherivier/fictional/issues/39

Since fictional didn't change most recently, I'm not sure why the error comes up now. Maybe it's ESM module related?

gweese commented 3 months ago

Also having this issue. Currently using the Prisma adapter. Previously working seeding is now broken, and I also tried it with the default test user example and both are throwing this exact same error in OP.

benjaminpreiss commented 3 months ago

Having a similar issue (reading 'trim')...

Fixed by using: pnpm dlx @snaplet/seed@0.97.20 generate

jmgunter commented 3 months ago

For me the issue turned out to be the latest release of tsx. Running npx tsx@4.16.2 seed.ts works.

CarelFdeWaal commented 3 months ago

Using latest tsx seems to solve the issue.

I tested with:

npx tsx --version
tsx v4.16.4
node v22.5.1

Will close issue soon if no more comment

Aietes commented 3 months ago

It works with tsx@4.16.2, thank you @jmgunter for finding this workaround!

@CarelFdeWaal I'm still getting the same error using the latest tsx.

❯ npx tsx --version
tsx v4.16.4
node v22.4.1

It seems the root cause for the issue has been identified upstream, and hopefully can be solved there: https://github.com/oftherivier/fictional/issues/39

Thank you for looking into this! And thank you for this great project!

Aietes commented 3 months ago

The upstream issue has been solved, things should work again without a workaround.

I had to reinstall all modules with pnpm after deleting the lock file and the node_modules folder to ensure the version of fictional that fixes the issue is in the dependencies.