Search code examples
javascriptnode.jstypescriptpostgresqlmikro-orm

Map files getting executed by Mikro ORM


I am a beginner learning Mikro-ORM and I keep running into an issue with my .map files. I am compiling my typescript into javascript and then executing the js with node. However, when I use node to execute the javascript, I run into the following error:

[query] begin
[query] select * from "mikro_orm_migrations" order by "id" asc [took 31 ms]
[query] select * from "mikro_orm_migrations" order by "id" asc [took 32 ms]
== Migration20210311015910.js: migrating =======
[query] rollback
/home/runner/fullstack-tut/dist/migrations/Migration20210311015910.js.map:1
{"version":3,"file":"Migration20210311015910.js","sourceRoot":"","sources":["../../src/migrations/Migration20210311015910.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,sDAAkD;AAElD,MAAa,uBAAwB,SAAQ,sBAAS;IAE9C,EAAE;;YACN,IAAI,CAAC,MAAM,CAAC,mJAAmJ,CAAC,CAAC;QACnK,CAAC;KAAA;CAEF;AAND,0DAMC"}
          ^

SyntaxError: Unexpected token ':'
    at wrapSafe (internal/modules/cjs/loader.js:915:16)
    at Module._compile (internal/modules/cjs/loader.js:963:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    at Module.require (internal/modules/cjs/loader.js:887:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Migrator.resolve (/home/runner/fullstack-tut/node_modules/@mikro-orm/migrations/Migrator.js:141:27)
    at Object.customResolver (/home/runner/fullstack-tut/node_modules/@mikro-orm/migrations/Migrator.js:43:44)
    at Migration.migration (/home/runner/fullstack-tut/node_modules/umzug/lib/migration.js:60:38)
    at /home/runner/fullstack-tut/node_modules/umzug/lib/migration.js:121:37
    at Generator.next (<anonymous>)
    at asyncGeneratorStep (/home/runner/fullstack-tut/node_modules/umzug/lib/migration.js:9:103)
    at _next (/home/runner/fullstack-tut/node_modules/umzug/lib/migration.js:11:194)
    at /home/runner/fullstack-tut/node_modules/umzug/lib/migration.js:11:364
    at new Promise (<anonymous>)

[query] rollback
/home/runner/fullstack-tut/dist/migrations/Migration20210311015910.js.map:1
{"version":3,"file":"Migration20210311015910.js","sourceRoot":"","sources":["../../src/migrations/Migration20210311015910.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,sDAAkD;AAElD,MAAa,uBAAwB,SAAQ,sBAAS;IAE9C,EAAE;;YACN,IAAI,CAAC,MAAM,CAAC,mJAAmJ,CAAC,CAAC;QACnK,CAAC;KAAA;CAEF;AAND,0DAMC"}
          ^

SyntaxError: Unexpected token ':'
    at wrapSafe (internal/modules/cjs/loader.js:915:16)
    at Module._compile (internal/modules/cjs/loader.js:963:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    at Module.require (internal/modules/cjs/loader.js:887:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Migrator.resolve (/home/runner/fullstack-tut/node_modules/@mikro-orm/migrations/Migrator.js:141:27)
    at Object.customResolver (/home/runner/fullstack-tut/node_modules/@mikro-orm/migrations/Migrator.js:43:44)
    at Migration.migration (/home/runner/fullstack-tut/node_modules/umzug/lib/migration.js:60:38)
    at /home/runner/fullstack-tut/node_modules/umzug/lib/migration.js:121:37
    at Generator.next (<anonymous>)
    at asyncGeneratorStep (/home/runner/fullstack-tut/node_modules/umzug/lib/migration.js:9:103)
    at _next (/home/runner/fullstack-tut/node_modules/umzug/lib/migration.js:11:194)
    at /home/runner/fullstack-tut/node_modules/umzug/lib/migration.js:11:364
    at new Promise (<anonymous>)

Currently, I have just been deleting these map files but I don't see this as a solution for me to continue going along. I have been searching for this issue for several hours and haven't found a question like this anywhere on StackOverflow. Thanks!


Solution

  • You have the ORM misconfigured, this is working based on migrations.pattern configuration, and apparently you are overriding the defaults (/^[\w-]+\d+\.ts$/), to something that also allows map files.

    Funny to see a question like this, while you did not share your ORM configuration (where you must have overriden quite a lot of things).

    For JS files you should do something like /^[\w-]+\d+\.js$/. As long as you know there will never be JS and TS files next to each other (so you have sources and dist in different folders), you could also do /^[\w-]+\d+\.[jt]s$/.

    You are most probably missing the $ at the end of the regexp.