由 Mikro ORM 执行的映射文件

Map files getting executed by Mikro ORM

我是一名学习 Mikro-ORM 的初学者,我一直 运行 遇到我的 .map 文件的问题。我正在将我的 typescript 编译成 javascript 然后用节点执行 js。但是,当我使用节点执行javascript时,我运行出现以下错误:

[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>)

目前,我刚刚删除了这些 map 文件,但我不认为这是让我继续前进的解决方案。我已经搜索这个问题几个小时了,但在 Whosebug 上的任何地方都没有找到这样的问题。谢谢!

您的 ORM 配置错误,这是基于 migrations.pattern 配置工作的,显然您正在覆盖默认设置 (/^[\w-]+\d+\.ts$/),使其也允许映射文件。

看到这样的问题很有趣,而你没有分享你的 ORM 配置(你一定已经覆盖了很多东西)。

对于 JS 文件你应该做类似 /^[\w-]+\d+\.js$/ 的事情。只要你知道永远不会有 JS 和 TS 文件彼此相邻(所以你在不同的文件夹中有 sources 和 dist),你也可以做 /^[\w-]+\d+\.[jt]s$/.

您很可能错过了正则表达式末尾的 $