rmp135 / sql-ts

Generate TypeScript interfaces from a SQL database.
MIT License
477 stars 65 forks source link

`import.meta.dirname` Crashes in Node 18 #143

Closed hhanesand closed 7 months ago

hhanesand commented 7 months ago

Hey there!

First off - thanks for maintaining this library 💚 We have been using the tool for 3-4 years now.

We're running node v18.20.1, and just tried upgrading to the v2 release. When running the tool I get this error:

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined
          at __node_internal_captureLargerStackTrace (node:internal/errors:496:5)
          at new NodeError (node:internal/errors:405:5)
          at validateString (node:internal/validators:162:11)
          at Module.join (node:path:1171:7)
          at Module.applyConfigDefaults (<...>/common/temp/node_modules/.pnpm/@rmp1sql-ts@2.0.1_pg@8.11.3/node_modules/@rmp135/sql-ts/src/ConfigTasks.ts:27:20)
          at Function.fromConfig (<...>/common/temp/node_modules/.pnpm/@rmp1sql-ts@2.0.1_pg@8.11.3/node_modules/@rmp135/sql-ts/src/Client.ts:73:33)
          at generateEntitiesFile (<...>/packages/database/bin/generate.ts:762:25)
          at generateApiEntitiesFile (<...>/packages/database/bin/generate.ts:689:3)
          at generateApiEntities (<...>/packages/database/bin/generate.ts:36:3)
          at async Promise.all (index 0)
          at main (<...>/packages/database/bin/generate.ts:31:3)
          at <anonymous> (<...>/packages/database/bin/generate.ts:676:1)

This seems to be the import.meta.dirname attribute being undefined for our Node version. I don't think that functionality is available yet in the v18 release line.

I am happy to provide a fix to this - it seems we either need to change this dirname to something using import.meta.url or document the v20 requirement. Any preferences?

hhanesand commented 7 months ago

Just saw #141 - this ticket is a dupe ✌️