You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
Using [email protected] with MIKRO_ORM_DYNAMIC_IMPORTS crashes on init
Stack trace
Error [ERR_MODULE_NOT_FOUND]: Cannot find module 'C:\dev\package.json' imported from C:\dev\project\node_modules\@mikro-orm\core\utils\Utils.js
at __node_internal_captureLargerStackTrace (node:internal/errors:464:5)
at new NodeError (node:internal/errors:371:5)
at finalizeResolution (node:internal/modules/esm/resolve:321:11)
at moduleResolve (node:internal/modules/esm/resolve:756:10)
at Loader.defaultResolve [as _resolve] (node:internal/modules/esm/resolve:867:11)
at Loader.resolve (node:internal/modules/esm/loader:89:40)
at Loader.getModuleJob (node:internal/modules/esm/loader:242:28)
at Loader.import (node:internal/modules/esm/loader:177:28)
at importModuleDynamically (node:internal/modules/cjs/loader:1041:29)
at importModuleDynamicallyWrapper (node:internal/vm/module:437:21)
at importModuleDynamically (node:vm:381:43)
at exports.importModuleDynamicallyCallback (node:internal/process/esm_loader:30:14)
at eval (eval at dynamicImport (C:\dev\project\node_modules\@mikro-orm\core\utils\Utils.js:684:16), <anonymous>:3:1)
at Function.dynamicImport (C:\dev\project\node_modules\@mikro-orm\core\utils\Utils.js:684:50)
at Function.checkPackageVersion (C:\dev\project\node_modules\@mikro-orm\core\utils\ConfigurationLoader.js:209:49)
at Function.init (C:\dev\project\node_modules\@mikro-orm\core\MikroORM.js:33:63)
at null.<anonymous> (C:\dev\project\src\db\index.ts:4:35)
at ModuleJob.run (node:internal/modules/esm/module_job:183:25)
at async Loader.import (node:internal/modules/esm/loader:178:24)
at async Object.loadESM (node:internal/process/esm_loader:68:5)
at async handleMainPromise (node:internal/modules/run_main:63:12)
Running in an ES Module project with MIKRO_ORM_DYNAMIC_IMPORTS enabled.
Running on Windows (not sure if this is OS-specific)
The path being requested is not relative to @mikro-orm/core, but should be. This is likely due to the use of pathToFileURL in Utils.dynamicImport, which will convert a relative path like "../package.json" to an absolute path using the current working directory (rather than relative to the importing module).
Even if the path were correct, you cannot use dynamic imports for JSON files in NodeJS without --experimental-json-modules. To load a package.json you should continue to use require if it is available, otherwise you should use fs.readFileSync.
Versions
Dependency
Version
node
16.6.2
typescript
4.5.4
mikro-orm
5.0.0-rc.3
your-driver
n/a
The text was updated successfully, but these errors were encountered:
The relative path is already fixed in master. I will try to use createRequire for this (we already have Utils.requireFrom() helper that does it), the docs says it should be still valid approach and we use that to check the TS version already.
Describe the bug
Using
[email protected]
withMIKRO_ORM_DYNAMIC_IMPORTS
crashes oninit
Stack trace
To Reproduce
Steps to reproduce the behavior:
@mikro-orm/[email protected]
MikroORM.init()
Expected behavior
No crash
Additional context
MIKRO_ORM_DYNAMIC_IMPORTS
enabled.@mikro-orm/core
, but should be. This is likely due to the use ofpathToFileURL
inUtils.dynamicImport
, which will convert a relative path like"../package.json"
to an absolute path using the current working directory (rather than relative to the importing module).--experimental-json-modules
. To load apackage.json
you should continue to userequire
if it is available, otherwise you should usefs.readFileSync
.Versions
The text was updated successfully, but these errors were encountered: