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

Add a way to run .ts files in Programmatic #1199

Open
BetaTH opened this issue Jun 13, 2024 · 8 comments
Open

Add a way to run .ts files in Programmatic #1199

BetaTH opened this issue Jun 13, 2024 · 8 comments
Labels
s: pending triage Pending Triage

Comments

@BetaTH
Copy link

BetaTH commented Jun 13, 2024

Description

Error: Can't get migration files: /workspaces/clone-tabnews/src/infra/migrations/1718242225526_test-migration.ts:2
import { MigrationBuilder, ColumnDefinitions } from 'node-pg-migrate';
^^^^^^

SyntaxError: Cannot use import statement outside a module

I get this erro if a try to run typescript migrations files, generated by node-pg-migrate -j ts create.
Its seems a ""ESM | commonJS"" problem, but in CLI i can run .ts directly

Suggested solution

In CLI i can run node-pg-migrate up with passing tsconfig.json as a flag with compilerOptions.module: "commonjs" to directly run .ts files, it would be nice if i could do the same in the programmatic approach

Alternative

No response

Additional context

No response

@BetaTH BetaTH added the s: pending triage Pending Triage label Jun 13, 2024
@Shinigami92
Copy link
Collaborator

Would you like to test out this? #1187 (comment)

@BetaTH
Copy link
Author

BetaTH commented Jun 13, 2024

Would you like to test out this? #1187 (comment)

Yes, i will try

@BetaTH
Copy link
Author

BetaTH commented Jun 13, 2024

@Shinigami92
Still getting the same error

Error: Can't get migration files: /workspaces/clone-tabnews/src/infra/migrations/1718242225526_test-migration.ts:2
import { MigrationBuilder, ColumnDefinitions } from 'node-pg-migrate';
^^^^^^

SyntaxError: Cannot use import statement outside a module

@Shinigami92
Copy link
Collaborator

Are you able to create a minimal reproducible repository I can checkout?

@aprendendofelipe
Copy link
Contributor

Could you test with node-pg-migrate-exp?

npm i node-pg-migrate-exp
import { ... } from 'node-pg-migrate-exp'

@BetaTH
Copy link
Author

BetaTH commented Jun 13, 2024

@aprendendofelipe It continues to work only in .js files with commonjs. In .ts with esm im getting the same error

@BetaTH
Copy link
Author

BetaTH commented Jun 13, 2024

@Shinigami92
you can use this repo
but go to branch test/node-pg-migrate-experimental that have your experimental version

  • run npm install
  • run npm run dev to up the server and database
  • run npm run test:watch --- migrations to test api endpoint (or call the endpoint /api/v1/migrations in the browser)

@Shinigami92
Copy link
Collaborator

thx, just to set expectation, I will need to consume free-time for that, hopefully I find some time tomorrow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
s: pending triage Pending Triage
Projects
None yet
Development

No branches or pull requests

3 participants