Open benrobson opened 2 years ago
This can be solved with dynamic import, which is supported in both cjs and esm. Lmk if anyone have already started to work on it, else I will be happy to create a pr to fix this.
How would I dynamic import with type module?
Get Outlook for Androidhttps://aka.ms/AAb9ysg
From: Parbez @.> Sent: Monday, January 10, 2022 1:34:57 PM To: AlexzanderFlores/WOKCommands @.> Cc: Ben Robson @.>; Author @.> Subject: Re: [AlexzanderFlores/WOKCommands] Support modules in NodeJS (Issue #201)
This can be solved with dynamic import, which is supported in both cjs and esm. Lmk if anyone have already started to work on it, else I will be happy to create a pr to fix this.
— Reply to this email directly, view it on GitHubhttps://github.com/AlexzanderFlores/WOKCommands/issues/201#issuecomment-1008497523, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ADVRDWD7JYE4KNMGO5JJOZTUVJAVDANCNFSM5LQI7LPA. You are receiving this because you authored the thread.Message ID: @.***>
How would I dynamic import with type module? Get Outlook for Androidhttps://aka.ms/AAb9ysg … ____ From: Parbez @.> Sent: Monday, January 10, 2022 1:34:57 PM To: AlexzanderFlores/WOKCommands @.> Cc: Ben Robson @.>; Author @.> Subject: Re: [AlexzanderFlores/WOKCommands] Support modules in NodeJS (Issue #201) This can be solved with dynamic import, which is supported in both cjs and esm. Lmk if anyone have already started to work on it, else I will be happy to create a pr to fix this. — Reply to this email directly, view it on GitHub<#201 (comment)>, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ADVRDWD7JYE4KNMGO5JJOZTUVJAVDANCNFSM5LQI7LPA. You are receiving this because you authored the thread.Message ID: @.***>
The issue is present in this lib not in your code. So you can create a pull request to solve the issue. You just need to change these require
to import
. It'll return a promise with an object like this Promise<{default: any}>
. You need to change it as required.
Would you or someone be able to make a PR to fix this as I'm unfamiliar with the WOK library and kind of new to it?
Get Outlook for Androidhttps://aka.ms/AAb9ysg
From: Parbez @.> Sent: Monday, January 10, 2022 1:48:58 PM To: AlexzanderFlores/WOKCommands @.> Cc: Ben Robson @.>; Author @.> Subject: Re: [AlexzanderFlores/WOKCommands] Support modules in NodeJS (Issue #201)
How would I dynamic import with type module? Get Outlook for Androidhttps://aka.ms/AAb9ysg … ____ From: Parbez @.> Sent: Monday, January 10, 2022 1:34:57 PM To: AlexzanderFlores/WOKCommands @.> Cc: Ben Robson @.>; Author @.> Subject: Re: [AlexzanderFlores/WOKCommands] Support modules in NodeJS (Issue #201https://github.com/AlexzanderFlores/WOKCommands/issues/201) This can be solved with dynamic import, which is supported in both cjs and esm. Lmk if anyone have already started to work on it, else I will be happy to create a pr to fix this. — Reply to this email directly, view it on GitHub<#201 (comment)https://github.com/AlexzanderFlores/WOKCommands/issues/201#issuecomment-1008497523>, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ADVRDWD7JYE4KNMGO5JJOZTUVJAVDANCNFSM5LQI7LPA. You are receiving this because you authored the thread.Message ID: @.***>
The issue is present in this lib not in your code. So you can create a pull request to solve the issue. You just need to change these require to import. It'll return a promise with an object like this Promise<{default: any}>. You need to change it as required.
— Reply to this email directly, view it on GitHubhttps://github.com/AlexzanderFlores/WOKCommands/issues/201#issuecomment-1008500988, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ADVRDWC6H2J4IDM7DG32UC3UVJCJVANCNFSM5LQI7LPA. You are receiving this because you authored the thread.Message ID: @.***>
I have attempted to look into this and changed wokcommands\dist\FeatureHandler.js:37
to: this.registerFeature(await import(file), fileName);
which gave me this error:
node:internal/errors:464
ErrorCaptureStackTrace(err);
^
Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only file and data URLs are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'c:'
at new NodeError (node:internal/errors:371:5)
at Loader.defaultResolve [as _resolve] (node:internal/modules/esm/resolve:839: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 FeatureHandler.setup (C:\Users\Ben\OneDrive\Documents\GitHub\ModularEnigma-zander-web\node_modules\wokcommands\dist\FeatureHandler.js:37:51) {
code: 'ERR_UNSUPPORTED_ESM_URL_SCHEME'
}
Revert all changes you made, and if your error is "ESM_MODULE_REQUIRE" or something of that sort, just remove "type": "module"
from package.json
.
Hey, I've recently refactored my project from commonjs to modules and since then WOKCommands refuses to work. Here is my error: https://sourceb.in/BBobXoD2Jr
It seems the error is in
node_modules\wokcommands\dist\FeatureHandler.js:37
I would love to use this package but it refuses to work and wouldn't want to edit the package.
Revert all changes you made, and if your error is "ESM_MODULE_REQUIRE" or something of that sort, just remove
"type": "module"
frompackage.json
.Hey, I've recently refactored my project from commonjs to modules and since then WOKCommands refuses to work. Here is my error: https://sourceb.in/BBobXoD2Jr It seems the error is in
node_modules\wokcommands\dist\FeatureHandler.js:37
I would love to use this package but it refuses to work and wouldn't want to edit the package.
He wants to work with module.
Correct, and WOKCommands is not working with module, so I am looking to see how to make it universal between the 2.
I have attempted to look into this and changed
wokcommands\dist\FeatureHandler.js:37
to:this.registerFeature(await import(file), fileName);
which gave me this error:node:internal/errors:464 ErrorCaptureStackTrace(err); ^ Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only file and data URLs are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'c:' at new NodeError (node:internal/errors:371:5) at Loader.defaultResolve [as _resolve] (node:internal/modules/esm/resolve:839: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 FeatureHandler.setup (C:\Users\Ben\OneDrive\Documents\GitHub\ModularEnigma-zander-web\node_modules\wokcommands\dist\FeatureHandler.js:37:51) { code: 'ERR_UNSUPPORTED_ESM_URL_SCHEME' }
await import
sends {default: value}
so u need to grab the default value. I'll try it if I get some time.
I have attempted to look into this and changed
wokcommands\dist\FeatureHandler.js:37
to:this.registerFeature(await import(file), fileName);
which gave me this error:node:internal/errors:464 ErrorCaptureStackTrace(err); ^ Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only file and data URLs are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'c:' at new NodeError (node:internal/errors:371:5) at Loader.defaultResolve [as _resolve] (node:internal/modules/esm/resolve:839: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 FeatureHandler.setup (C:\Users\Ben\OneDrive\Documents\GitHub\ModularEnigma-zander-web\node_modules\wokcommands\dist\FeatureHandler.js:37:51) { code: 'ERR_UNSUPPORTED_ESM_URL_SCHEME' }
await import
sends{default: value}
so u need to grab the default value. I'll try it if I get some time.
In this case try using the path.join(__dirname, "commands")
or fileURLToPath
, if I understood well the error
It's not really the solution you want but with PR #209 you can use modules except for the commands themselves, which would be .cjs
(.cts
). It's just a question of whether it'll be merged. If not, you can change the single line of code locally in the node_modules directory.
Hey, I've recently refactored my project from commonjs to modules and since then WOKCommands refuses to work. Here is my error: https://sourceb.in/BBobXoD2Jr
It seems the error is in
node_modules\wokcommands\dist\FeatureHandler.js:37
I would love to use this package but it refuses to work and wouldn't want to edit the package.