Skip to content
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

Trying to link model throws '...is not linkable on service...' error #8147

Closed
intrinsic-blockchain opened this issue Jul 16, 2024 · 20 comments
Closed

Comments

@intrinsic-blockchain
Copy link

Reference: https://docs.medusajs.com/v2/resources/recipes/marketplace/examples/vendors

Bug report

I run into the following error:
Error: Key vendor_id is not linkable on service marketplaceModuleService
at register (C:\Users\hanee\Documents\medusajs\medusa-preview\node_modules@medusajs\utils\src\modules-sdk\define-link.ts:153:13)
at MedusaApp_ (C:\Users\hanee\Documents\medusajs\medusa-preview\node_modules@medusajs\modules-sdk\src\medusa-app.ts:385:30)
at async MedusaAppMigrateGenerate (C:\Users\hanee\Documents\medusajs\medusa-preview\node_modules@medusajs\modules-sdk\src\medusa-app.ts:594:34)
at async runMedusaAppMigrations (C:\Users\hanee\Documents\medusajs\medusa-preview\node_modules@medusajs\medusa\src\loaders\medusa-app.ts:127:5)
at async main (C:\Users\hanee\Documents\medusajs\medusa-preview\node_modules@medusajs\medusa\src\commands\migrate.ts:100:5)

Describe the bug

After defining models and then creating links between models, when npx medusa migrations generate is run, I see the following error Error: Key vendor_id is not linkable on service marketplaceModuleService

System information

Medusa version (including plugins): "preview" version
Node.js version: 20.5.1
Database: postgreSQL 16
Operating system: Windows 11

Steps to reproduce the behavior

  1. Follow steps 1 & 2 to create a module, models and links from the recipe https://docs.medusajs.com/v2/resources/recipes/marketplace/examples/vendors
  2. On step 3 when npx medusa migrations generate marketplaceModuleService is run, you see the error Error: Key vendor_id is not linkable on service marketplaceModuleService

Expected behavior

I expect the migration to generate and when migration is run, it should run without errors.

Screenshots

image
image
image
image
image

@adrien2p
Copy link
Member

hey @intrinsic-blockchain could you share you packages preview versions please

@intrinsic-blockchain
Copy link
Author

@adrien2p thanks for checking. Here is what I have:
@medusajs/medusa@1.20.6-preview-20240716090543
@medusajs/medusa-cli@1.3.23-preview-20240716090543

@shahednasser
Copy link
Member

Hi @intrinsic-blockchain , can you try removing the node_modules and yarn.lock files and trying again? This could be due to an outdated preview version.

@intrinsic-blockchain
Copy link
Author

@shahednasser deleting the node_modules & yarn.lock did not help. The migrations run successfully only if I comment out the files src/links/vendor-admin.ts & src/links/vendor-order.ts
image
image
image

@shahednasser
Copy link
Member

Is the issue with running or generating the migration? So if you run npx medusa migrations run do the links also cause an error?

@intrinsic-blockchain
Copy link
Author

intrinsic-blockchain commented Jul 17, 2024

Issue is with generating the migration with the command npx medusa migrations generate marketplaceModuleService. I think its unable to create the link between vendor & product models. Same with vendor-order models. It throws the Error: Key vendor_id is not linkable on service marketplaceModuleService error.

If its helpful this is what I have in vendor-product.ts in src/links folder,
image

hovering over MarketplaceModule.linkable.vendor shows this.
image

(property) vendor: {
id: {
serviceName: "marketplaceModuleService";
field: "vendor";
linkable: "vendor_id";
primaryKey: "id";
};
toJSON: () => {
serviceName: "marketplaceModuleService";
field: "vendor";
linkable: "vendor_id";
primaryKey: "id";
};
}

@shahednasser
Copy link
Member

Ok but if you run npx medusa migrations run (with the link files) you see no errors right?

@intrinsic-blockchain
Copy link
Author

intrinsic-blockchain commented Jul 17, 2024

I see this error WITH the links files

image

@adrien2p
Copy link
Member

@intrinsic-blockchain would you be able to provide us a minimal repository that reproduces this issue?

@intrinsic-blockchain
Copy link
Author

@shahednasser
Copy link
Member

@intrinsic-blockchain can you try to download this file and use it as yarn.lock in your project, re-install the dependencies, and try again?

https://res.cloudinary.com/dza7lstvk/raw/upload/v1721221052/OpenApi/yarn_ivml2e.lock

@intrinsic-blockchain
Copy link
Author

Unfortunately, using this yarn.lock file too didn't help. I still get the same error. I tried testing using yarn command as well as npm to install node modules, both the times see the same issue.

@imash96
Copy link

imash96 commented Jul 19, 2024

image
Getting same error while generating migrations

@adrien2p
Copy link
Member

I think I know what is the issues, I am preparing a pr so that you can test as well #8194

@adrien2p
Copy link
Member

Would you be able to test the snapshot generate here please

@imash96
Copy link

imash96 commented Jul 19, 2024

Yes issue is resolve thanks you very much @adrien2p

@adrien2p
Copy link
Member

wonderful, cc @shahednasser

@adrien2p
Copy link
Member

I ll close this issue as it is resolved for windows users as well 👍

@intrinsic-blockchain
Copy link
Author

@adrien2p thanks for all the support. I can confirm that doing an npm update and taking the latest build works just fine as expected. Thanks again for all the help!

@alisafavi
Copy link

Hey all, how can have a page to register new vender before login

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants