Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

typegen: Cannot find package execa, config being ignored #429

Open
litoj opened this issue Sep 4, 2024 · 5 comments
Open

typegen: Cannot find package execa, config being ignored #429

litoj opened this issue Sep 4, 2024 · 5 comments

Comments

@litoj
Copy link

litoj commented Sep 4, 2024

$ yarn pgkit-typegen generate

Using default connection URI of postgresql://postgres:postgres@localhost:5432/postgres
Using default pool config - type parsers will not be respected.
Matching files in ./src with pattern **/*.{ts,sql} excluding **/node_modules/**
Starting initial codegen
Searching for files.
Found 25 files matching criteria.
./src/database/index.ts:8 [!] Extracting types from query failed: Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'execa' imported from /home/kepis/Documents/work/vmw/backend/node_modules/@pgkit/typegen/dist/pg/
psql.js.
./src/database/index.ts finished. Processed 0/1 queries.
Finished processing 0/1 queries in 0/25 files.
Initial codegen complete

It also seems that my exclude pattern was ignored, because it should've found 2 files, not all files in the src directory.

config

/** @type {import('@pgkit/typegen').Options} */
export default {
  include: ['db/create.sql', 'src/database/*.ts'],
  exclude: ['**/*'],
};

after installing execa, I got: ...TypeError: execa is not a function.

@litoj litoj changed the title Cannot find package execa typegen: Cannot find package execa Sep 4, 2024
@mmkal
Copy link
Owner

mmkal commented Sep 4, 2024

Re the missing execa, I am working on a partial rewrite of typegen right now (so in general bear with me!) - try npm install @pgkit/typegen@0.2.4-0, that particular problem will hopefully go away. (you probably got execa is not a function after installing manually because typegen is still on a previous version of execa which used default exports).

Re the exclude pattern, it might be a couple of things - maybe the config file is being ignored completely for some reason? What is it named and how are you invoking the CLI?

@litoj
Copy link
Author

litoj commented Sep 5, 2024

Using a specific version did allow me to launch it, but - I'm still facing the issue with the config being ignored.

When I don't have the config as advised by the docs, the program crashes with:

$ yarn pgkit-typegen generate

Using default connection URI of postgresql://postgres:postgres@localhost:5432/postgres
Using default pool config - type parsers will not be respected.
Matching files in ./src with pattern **/*.{ts,sql} excluding **/node_modules/**
Starting initial codegen
Searching for files.
Found 26 files matching criteria.
Finished processing 0 queries in 0/26 files.
Initial codegen complete

node:internal/modules/esm/resolve:257
    throw new ERR_MODULE_NOT_FOUND(
          ^

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/home/kepis/Documents/work/vmw/backend/typegen.config.
js' imported from /home/kepis/Documents/work/vmw/backend/node_modules/@pgkit/typegen/dist/cli.js
    at finalizeResolution (node:internal/modules/esm/resolve:257:11)
    at moduleResolve (node:internal/modules/esm/resolve:914:10)
    at defaultResolve (node:internal/modules/esm/resolve:1038:11)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:554:12)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:523:25)
    at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:246:38)
    at onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:481:36)
    at TracingChannel.tracePromise (node:diagnostics_channel:337:14)
    at ModuleLoader.import (node:internal/modules/esm/loader:480:21)
    at defaultImportModuleDynamicallyForScript (node:internal/modules/esm/utils:227:31) {
  code: 'ERR_MODULE_NOT_FOUND',
  url: 'file:///home/kepis/Documents/work/vmw/backend/typegen.config.js'
}

Node.js v22.8.0

With the config file in the right place:

Using default connection URI of postgresql://postgres:postgres@localhost:5432/postgres
Using default pool config - type parsers will not be respected.
Matching files in ./src with pattern **/*.{ts,sql} excluding **/node_modules/**
...

Unfortunately, even with the config path provided to the cli, the config in its entirety seems to not work, though yet with another different error structure:

$ yarn pgkit-typegen generate --config typegen.config.js

(node:29008) [MODULE_TYPELESS_PACKAGE_JSON] Warning: file:///home/kepis/Documents/work/vmw/backend/typeg
en.config.js parsed as an ES module because module syntax was detected; to avoid the performance penalty
 of syntax detection, add "type": "module" to /home/kepis/Documents/work/vmw/backend/package.json
(Use `node --trace-warnings ...` to show where the warning was created)
Using default connection URI of postgresql://postgres:postgres@localhost:5432/postgres
Using default pool config - type parsers will not be respected.

Error: Unexpected configuration keys: connectionURI

Tried with config:

import 'dotenv/config';

/** @type {import('@pgkit/typegen').Options} */
export default {
  rootDir: 'src',
  include: ['../db/schema.sql', '../src/database/**.ts'],
  exclude: ['**/*.ts'],
  connectionURI: `postgresql://${process.env.DATABASE_URI}`,
};

I discovered sql-ts that generates types from db schema, which was the main thing I needed. Typegen, though unfortunate, isn't critical to the workflow, so I can keep using pgkit.

@litoj litoj changed the title typegen: Cannot find package execa typegen: Cannot find package execa, config being ignored Sep 5, 2024
@litoj
Copy link
Author

litoj commented Sep 12, 2024

I figured out from the typegen source code that the docs were supposed to say connectionString, yet, the config file is ignored by default, though it breaks without having it present at all - weird.

Now I'm stuck with all queries at Extracting types from query failed: AssertionError [ERR_ASSERTION]: No regtype found!.

@mmkal
Copy link
Owner

mmkal commented Sep 13, 2024

You happen to have been using this at a time where a ton of stuff was being worked on in the typegen package. Do you still get that error on version 0.2.4? (npm install @pgkit/client@0.2.4 @pgkit/typegen@0.2.4)

If you do, could you share either the full stack trace, or even better, the repo you're working on or a smaller reproduction repo?

@litoj
Copy link
Author

litoj commented Sep 15, 2024

I fixed some error in the typegen, where it erroring out on not finding a type for the last "Column" that postgres always sent - (x columns). Even after that it was still erroring out on some sql where I made some json aggregations. It cannot know what json I'm making, so it wouldn't have helped that much anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants