romeerez/orchid-orm

[typescript] Error when trying to run seed command

Closed this issue · 5 comments

After upgrading to the recent versions of all dependencies for OrchidORM, I can't run seeds due to the following error, using the same playground repo as in #196.

The repo setup runs migrations just fine, and the codebase is used for a separate project with an unchanged table definition, and the project runs and pulls data, queries, etc, just fine.

The issue only occurs while running pnpm run db seed command. See error output below.

λ › pnpm run db seed                                                                                                                                                                                                                                                                  [15:58:19]

> orchidorm-db-playground@0.1.0 db /Users/mmorek/Projects/playairsoft/orchidorm-db-playground
> node -r ts-node/register src/db/dbScript.ts "seed"

/Users/mmorek/Projects/playairsoft/orchidorm-db-playground/src/db/tables/Location.ts:12
export class LocationTable extends BaseTable {
^
TypeError: Class constructor _a cannot be invoked without 'new'
    at new LocationTable (/Users/mmorek/Projects/playairsoft/orchidorm-db-playground/src/db/tables/Location.ts:12:1)
    at orchidORM (/Users/mmorek/Projects/playairsoft/orchidorm-db-playground/node_modules/.pnpm/orchid-orm@1.17.27_typescript@5.2.2/node_modules/orchid-orm/src/orm.ts:152:19)
    at Object.<anonymous> (/Users/mmorek/Projects/playairsoft/orchidorm-db-playground/src/db/db.ts:14:28)
    at Module._compile (node:internal/modules/cjs/loader:1241:14)
    at Module.m._compile (/Users/mmorek/Projects/playairsoft/orchidorm-db-playground/node_modules/.pnpm/ts-node@10.9.1_@types+node@20.8.4_typescript@5.2.2/node_modules/ts-node/src/index.ts:1618:23)
    at Module._extensions..js (node:internal/modules/cjs/loader:1295:10)
    at Object.require.extensions.<computed> [as .ts] (/Users/mmorek/Projects/playairsoft/orchidorm-db-playground/node_modules/.pnpm/ts-node@10.9.1_@types+node@20.8.4_typescript@5.2.2/node_modules/ts-node/src/index.ts:1621:12)
    at Module.load (node:internal/modules/cjs/loader:1091:32)
    at Function.Module._load (node:internal/modules/cjs/loader:938:12)
    at Module.require (node:internal/modules/cjs/loader:1115:19)

This is due to an empty tsconfig file generated when initializing the project. npx tsc --init generates a working tsconfig.

Okay, so it looks like my tsconfig.json settings were incompatible with those expected by Orchid.

Adding target seem to have rectified it. Thanks!

Here's a gist of a basic Next.js 13.4 tsconfig.json with Next-specific options removed in a diff:

{
  "compilerOptions": {
-   "baseUrl": ".",
-   "paths": {
-     "@/*": [
-       "src/*"
-     ]
-   },
-   "lib": [
-     "dom",
-     "dom.iterable",
-     "esnext"
-   ],
+   "target": "esnext",
-   "allowJs": true,
    "skipLibCheck": true,
-   "strict": false,
    "forceConsistentCasingInFileNames": true,
-   "noEmit": true,
-   "incremental": true,
    "esModuleInterop": true,
    "module": "commonjs",
-   "moduleResolution": "node",
-   "resolveJsonModule": true,
-   "isolatedModules": true,
    "strict": true,
  },
- "ts-node": {
-   "esm": true
- },
- "include": [
-   "**/*.ts",
-   "**/*.tsx"
- ],
  "exclude": [
    "node_modules",
    "gitignored"
  ]
}

So currently orchid-orm is generating an almost empty tsconfig, which somehow worked before, but it needs to be fixed so I think to populate the same content as tsc --init does.

Also init script is asking to add swc, but it doesn't work with latest ts versions.

And there are other nuances. In the future would be cool to have ready templates with popular frameworks and tools, but that's a lot of work to do. At this stage, I just will make sure it works with various package managers and is producing a minimal working code.

I agree, there's no need to being framework specific, though an option to diff changes would be nice so it doesn't override anything important. Not sure is tsc has this capability though.

The init script is checking if there is a tsconfig already, if yes - it's not touched, and I think it's right that if you have it already, it's in your responsibility. And if there is no tsconfig, a very minimal one is created, and I need to add more configs to it.