-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: AwilixResolutionError: Could not resolve 'product' in custom module loader. #10946
Comments
Hey @jgatto1, This is expected. The module loader inside will only load dependencies that it specifically has access to. You are trying to load an external module here within a module which isn't supported. This is keeping in mind the module isolation principles. If you're looking to run cross module logic, you'd have to do that once all modules are loaded - for example, as a script or in the http layer. This is why it works within the http endpoint, but not the module loader. |
@riqwan I see. Thanks for your explanation! I'm trying to integrate Medusa with an external system mapping external products with Medusa products, so the idea is to subscribe to an event bus and there create the association between both products. I put the subscriber in the loader, but I'm not sure if there is an alternative to this. What do you think? Thanks! |
If you mean by this subscriber, then yes that sounds like a good approach. If not, a bit more details on what the setup looks like would help. |
@riqwan I meant a loader. Our idea was to subscribe in the loader to our internal emitted events. The loader is waiting for new events and then links Medusa Products with our custom products. But we can't call Product's module. I think using a loader is a better idea, instead of for example making a call from our custom app to create the products in Medusa. I really appreciate your help! |
You can create a workflow on your custom module, and in your loader you can subscribe to the events, and run this workflow when you have a new event. // modules/your_custom/workflows/test.ts
import { Modules } from "@medusajs/framework/utils";
import { createStep, createWorkflow } from "@medusajs/framework/workflows-sdk";
const step1 = createStep("step-1", async (_, context) => {
const prod = context.container.resolve(Modules.PRODUCT);
console.log(await prod.listProductCategories());
});
const myWorkflow = createWorkflow("sync-stuff", function (input) {
step1();
});
export default myWorkflow; // modules/your_custom/loaders/test.ts
import { LoaderOptions } from "@medusajs/framework/types";
import myWorkflow from "../workflows/test";
export default async function yourLoader({ container }: LoaderOptions) {
// subscribe to the events
setTimeout(async () => {
await myWorkflow.run();
}, 2000);
} |
Package.json file
Node.js version
v20.17.0
Database and its version
PostgreSQL 13.16
Operating system name and version
MacOS 14.0 (23A344)
Browser name
No response
What happended?
I can't load the product module on my custom module loader.
The file is in: src/modules/lms/loaders/lms.ts
with content:I'm adding it to my
src/modules/lms/index.ts
file.But when I use the same in a route for example it works.
Btw, when I resolve
container.resolve(ContainerRegistrationKeys.LOGGER);
it works in my custom loader.Expected behavior
It should resolve product module.
Actual behavior
Is not resolving the product module in my custom module loader.
Link to reproduction repo
not apply
The text was updated successfully, but these errors were encountered: