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

Migration does not work with node 18.19.0 #10537

Open
18 tasks
chrisrusselltred opened this issue Dec 4, 2023 · 6 comments
Open
18 tasks

Migration does not work with node 18.19.0 #10537

chrisrusselltred opened this issue Dec 4, 2023 · 6 comments

Comments

@chrisrusselltred
Copy link

Issue description

typeorm-ts-node-esm migration:run -d does not work with node 18.19

Expected Behavior

typeorm-ts-node-esm migration:run should run the migration process as described
https://orkhan.gitbook.io/typeorm/docs/migrations

This works for node versions 18.18.x

Actual Behavior

Under node version 18.19.0 an error is thrown.

Error during migration run:
Error: Unable to open file: . Cannot use import statement outside a module

Steps to reproduce

Create a file with a function called createDatasource() that returns a Datasource
Create a file called instance.ts what contains

import { createDataSource } from '.';
export const AppDataSource = createDataSourceV2();

run "typeorm-ts-node-esm migration:run -d ./instance.ts" under node 18.19.0

My Environment

    |

| Node.js version | 18.19.0 |
| Typescript version | 5.2.2 |
| TypeORM version | 0.3.17 |

Additional Context

No response

Relevant Database Driver(s)

  • aurora-mysql
  • aurora-postgres
  • better-sqlite3
  • cockroachdb
  • cordova
  • expo
  • mongodb
  • mysql
  • nativescript
  • oracle
  • postgres
  • react-native
  • sap
  • spanner
  • sqlite
  • sqlite-abstract
  • sqljs
  • sqlserver

Are you willing to resolve this issue by submitting a Pull Request?

No, I don’t have the time and I’m okay to wait for the community / maintainers to resolve this issue.

@OriginalRoOhi
Copy link

same issue when running migrations inside node:18-alpine docker image. it was working fine a few days ago.

@jaymovaliya
Copy link

Yes, I am also facing the same issue for the last couple of days. Migrations inside my node:18-alpine Docker image are not working, and it's giving this error

Error during migration run:
Error: Unable to open file: . Cannot use import statement outside a module

@joebrewr
Copy link

I am getting the same problem and can confirm that using Node 18.18.0 is fine but 18.19.0 is not. I've attempted migrations using both typeorm-ts-node-esm (with ./datasource.ts) and typeorm-ts-node-commonjs (with ./build/datasource.js) and neither works. The errors are slightly different, though.

For typeorm-ts-node-esm I get (same as others have seen):

Error: Unable to open file: "./dataSource.ts". Cannot use import statement outside a module

For typeorm-ts-node-commonjs I get:

Error: Connection lost: The server closed the connection.

@klangenk
Copy link

klangenk commented Feb 1, 2024

The problem also occurs on Node 20.11

We could fix this problem by switching from typeorm-ts-node-esm to typeorm-ts-node-commonjs like mentioned in the docs without changing anything else.

@joebrewr You can still use "./datasource.ts" with typeorm-ts-node-commonjs.

Seems like typeorm-ts-node-esm was also working for CommonJS projects before Node 18.19, but since 18.19 it only works for ESM projects.

@joebrewr
Copy link

joebrewr commented Feb 8, 2024

Thanks, @klangenk. I think I must've been seeing an unrelated error when running typeorm-ts-node-commonjs previously because your suggestion has worked (using ./datasource.ts rather than ./build/datasource.js)

@ItsTarik
Copy link

Its a big mess ! how to pass -r tsconfig-paths/register like useal ts-node when using path alias with typescript ?

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

No branches or pull requests

6 participants