ilovepixelart / ts-migrate-mongoose

A node/typescript based migration framework for mongoose
MIT License
66 stars 5 forks source link

Possibly a problem with dynamic import #228

Closed tipoc123 closed 10 months ago

tipoc123 commented 10 months ago

Describe the bug Locally everything works well:

Снимок экрана 2023-11-22 в 06 37 25

But it doesn’t work in kubernetes:

Снимок экрана 2023-11-22 в 06 33 18

According to logs it gets stuck on dynamic import:

https://github.com/ilovepixelart/ts-migrate-mongoose/blob/15173ae49248d217e6e88edfb079fc3de0ad80f6/src/migrator.ts#L411

What could be the problem?

And what do empty curly braces ({}) at the end of logs mean?

Additional context

tipoc123 commented 10 months ago

I even simplified the migration file to a single console.log call (for testing purposes):

Снимок экрана 2023-11-22 в 07 11 53
ilovepixelart commented 10 months ago

This looks like SWC issue in relation to distro, my automated tests are running on ubuntu-latest Which distro is used in your docker container?

tipoc123 commented 10 months ago

FROM node:18.12.1

Is this information enough?

ilovepixelart commented 10 months ago

Made an example it's working with your node:18.12.1

image

Check https://github.com/ilovepixelart/ts-express-swc/commit/7ce8578701139fdd255d1e175cfdd948e2aa5a52

tipoc123 commented 10 months ago

Any other ideas what could be the problem?

ilovepixelart commented 10 months ago

Same example with nets all works, I think it's your setup closing this issue https://github.com/ilovepixelart/ts-express-nest

image
tipoc123 commented 9 months ago

I wrapped the import in try-catch and this is the error in the logs:

/opt/nest-api/migrations/1699935100948-drop-orders.ts:1
import * as mongoose from 'mongoose';
^^^^^^
SyntaxError: Cannot use import statement outside a module
at Object.compileFunction (node:vm:360:18)
at wrapSafe (node:internal/modules/cjs/loader:1088:15)
at Module._compile (node:internal/modules/cjs/loader:1123:27)
at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
at Object.newLoader [as .ts] (/opt/nest-api/node_modules/pirates/lib/index.js:104:7)
at Module.load (node:internal/modules/cjs/loader:1037:32)
at Function.Module._load (node:internal/modules/cjs/loader:878:12)
at Module.require (node:internal/modules/cjs/loader:1061:19)
at require (node:internal/modules/cjs/helpers:103:18)
at /opt/nest-api/src/ts-migrate-mongoose/migrator.ts:519:28
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at Migrator.runMigrations (/opt/nest-api/src/ts-migrate-mongoose/migrator.ts:518:31)
at Migrator.run (/opt/nest-api/src/ts-migrate-mongoose/migrator.ts:209:27)
at runMigrations (/opt/nest-api/src/migrator.ts:45:3)
at AppBootstrap.bootstrap (/opt/nest-api/src/main.ts:118:5)
Снимок экрана 2023-12-14 в 00 47 01

But it works locally.

Start of my migration file:

import * as mongoose from 'mongoose';
import * as process from 'process';

import { migratorLog } from '../src/migrator';

export async function up(): Promise<void> {
   ...
}