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
I create a brand module step by step from medusa instructions and it works well, but when i try to create a Module named Media to save address of uploaded images for later use, it throws type error on all default medusa generated function like (TypeError: mediaModuleService.listAndCountMedias is not a function, TypeError: mediaModuleService.createMedias is not a function).
after some struggle i find the problem, something related to generate naming of functions by medusa is wrong, medusa tries to create collective nouns for medusa services methods, but at least for media that doesn't work!
how to fix this?
just drop "s" from end of the name of auto generated methods and it works.
for example:
what medusa create: await mediaModuleService.listAndCountMedias()
what works : await mediaModuleService.listAndCountMedia()
(default generated methods worked for brand)
Codes to reproduce:
modules/media/models/media.ts
import { model } from "@medusajs/framework/utils";
export const Media = model.define("media", {
id: model.id().primaryKey(),
name: model.text().searchable(),
url: model.text(),
});
modules/media/service.ts
import { MedusaService } from "@medusajs/framework/utils";
import { Media } from "./models/media";
class MediaModuleService extends MedusaService({
Media,
}) {}
export default MediaModuleService;
We use pluralize to infer the singular and plural forms of the data models when creating the service methods. The plural form of media is media, so this is expected behavior. Or rather, the noun media does not have a plural form, as per their source code.
Package.json file
Node.js version
v22.9.0
Database and its version
14.4
Operating system name and version
Win10
Browser name
What happended?
I create a brand module step by step from medusa instructions and it works well, but when i try to create a Module named Media to save address of uploaded images for later use, it throws type error on all default medusa generated function like (TypeError: mediaModuleService.listAndCountMedias is not a function, TypeError: mediaModuleService.createMedias is not a function).
after some struggle i find the problem, something related to generate naming of functions by medusa is wrong, medusa tries to create collective nouns for medusa services methods, but at least for media that doesn't work!
how to fix this?
just drop "s" from end of the name of auto generated methods and it works.
for example:
what medusa create: await mediaModuleService.listAndCountMedias()
what works : await mediaModuleService.listAndCountMedia()
(default generated methods worked for brand)
Codes to reproduce:
modules/media/service.ts
modules/media/index.ts
medusa-config.ts
Expected behavior
it must create correct types or names for ModuleService methods.
Actual behavior
it throws type error when you try to use ModuleService methods.
Link to reproduction repo
https://github.com/FarNys/medusa2_backend
The text was updated successfully, but these errors were encountered: