skip to Main Content

I am setting up medusaJS with Strapi by default command https://docs.medusajs.com/plugins/cms/strapi

I did setup Redis, medusa cli, was using Node version 16,18. However, I got this issue

Now using node v18.13.0 (npm v8.19.3)
❯ npx create-strapi-app strapi-medusa --template shahednasser/strapi-medusa-template
? Choose your installation type Quickstart (recommended)
Creating a quickstart project.
Creating a new Strapi application at /Users/felixle/Downloads/6github_new/strapi-medusa.
Creating files.
Installing strapi-medusa-template template.
Dependencies installed successfully.
Initialized a git repository.


Your application was created at /Users/felixle/Downloads/6github_new/strapi-medusa.

Available commands in your project:

  yarn develop
  Start Strapi in watch mode. (Changes in Strapi project files will trigger a server restart)

  yarn start
  Start Strapi without watch mode.

  yarn build
  Build Strapi admin panel.

  yarn strapi
  Display all available commands.

You can start by doing:

  cd /Users/felixle/Downloads/6github_new/strapi-medusa
  yarn develop

Running your Strapi application.

> [email protected] develop
> strapi develop

Building your admin UI with development configuration...
Admin UI built successfully
ApplicationError: The type is required
    at getFieldSize (/Users/felixle/Downloads/6github_new/strapi-medusa/node_modules/@strapi/plugin-content-manager/server/services/field-sizes.js:57:15)
    at getDefaultFieldSize (/Users/felixle/Downloads/6github_new/strapi-medusa/node_modules/@strapi/plugin-content-manager/server/services/utils/configuration/layouts.js:34:10)
    at appendToEditLayout (/Users/felixle/Downloads/6github_new/strapi-medusa/node_modules/@strapi/plugin-content-manager/server/services/utils/configuration/layouts.js:139:27)
    at createDefaultEditLayout (/Users/felixle/Downloads/6github_new/strapi-medusa/node_modules/@strapi/plugin-content-manager/server/services/utils/configuration/layouts.js:56:10)
    at createDefaultLayouts (/Users/felixle/Downloads/6github_new/strapi-medusa/node_modules/@strapi/plugin-content-manager/server/services/utils/configuration/layouts.js:40:11)
    at createDefaultConfiguration (/Users/felixle/Downloads/6github_new/strapi-medusa/node_modules/@strapi/plugin-content-manager/server/services/utils/configuration/index.js:26:20)
    at async generateNewConfiguration (/Users/felixle/Downloads/6github_new/strapi-medusa/node_modules/@strapi/plugin-content-manager/server/services/configuration.js:53:36)
    at async Promise.all (index 13)
    at async Object.syncConfigurations (/Users/felixle/Downloads/6github_new/strapi-medusa/node_modules/@strapi/plugin-content-manager/server/services/configuration.js:67:5)
    at async module.exports [as bootstrap] (/Users/felixle/Downloads/6github_new/strapi-medusa/node_modules/@strapi/plugin-content-manager/server/bootstrap.js:7:3) {
  details: {}
}

Could you please help me?

Thanks

The project can run

2

Answers


  1. Chosen as BEST ANSWER

    We cannot resolve it from our side because it is from the source code of Medusa.

    I format the data by a function, then import the result into postgres DB.

    const fs = require('fs');
    
    // Function to format a single item
    // Function to format a single item
    const formatDbItem = (product) => {
      const result = {
        title: product.title,
        subtitle: null,
        description: product.body_html,
        handle: product.handle,
        weight: 0,
        is_giftcard: false,
        images: product.images.map((image) => image.src),
        options: product.options.map((option) => ({
          title: option.name,
          values: [option.values].flat(), // Flatten the values array
        })),
        variants: product.variants.map((variant) => {
          const variantObj = {
            title: variant.title,
            // data of prices should be in an array
            prices: [
              {
                currency_code: 'cad',
                amount: Math.floor(parseInt(variant.price) * 100),
              },
              {
                currency_code: 'usd',
                amount: Math.floor(parseInt(variant.price) * 100 * 1.25),
              },
              {
                currency_code: 'eur',
                amount: Math.floor(parseInt(variant.price) * 100 * 1.5),
              },
            ],
            options: Object.keys(variant)
              .filter((key) => key.startsWith('option'))
              .map((key) => {
                const value = variant[key];
                if (value !== null) {
                  return { value };
                }
              })
              .filter(Boolean), // Filter out undefined values
            inventory_quantity: variant.inventory_quantity,
            manage_inventory: true,
          };
          return variantObj;
        }),
      };
      return result;
    };
    
    // Read the contents of productsShopify.json
    const originalData = fs.readFileSync('data/productsShopify.json');
    const jsonData = JSON.parse(originalData);
    // Apply formatDbItem function to each item
    const formattedData = jsonData.products.map(formatDbItem);
    
    // Write the modified data to a new JSON file
    fs.writeFileSync('data/formattedProducts.json', JSON.stringify(formattedData));

    So, if you need more help please inform me.

    Best wish


  2. As others have suggested, it has nothing to do with the source code of medusa per se. The problem you’re getting is a missing type field in a schema.

    This part of the code, where you are getting the error from, parses the schema.json files in the content-types folders under src/api/[content-type-name]/content-types/[content-type-name]. You will notice with the specific template you’ve chosen that not all attributes in this schema.json files have a type field.

    Strapi v4 introduced major changes in its schema structures. Some of the migrations to v4 can be applied automatically as it happened with shahednasser/strapi-medusa-template. But some are manually, which weren’t applied to that directory. You need to migrate the rest of the changes in the schema files to Strapi v4s new format and everything should work.

    Just for reference, here is a snippet from the payment-provider content-type in v3 and then v4

    v3:

    "regions": {
          "via": "payment_providers",
          "collection": "region"
        }
    

    v4:

    "regions": {
          "type": "relation",
          "relation": "manyToMany",
          "target": "api::region.region",
          "inversedBy": "payment_providers"
        }
    

    Some people did this already, so I took the schema files from this repository and wrote a simple Python script to replace all the files from the mentioned repository to the template from shahednasser:

    import os
    import shutil
    
    # Define the source directory where the new schema.json files are located
    source_dir = "src/api"
    
    # Define the target directory where the existing schema.json files are located which should be replaced
    target_dir = "strapi-medusa/src/api"
    
    # Iterate over all the subdirectories in the target directory
    for subdir, dirs, files in os.walk(target_dir):
        for file in files:
            # Check if the current file is a schema.json file
            if file == "schema.json":
                # Define the path to the current schema.json file
                current_file_path = os.path.join(subdir, file)
    
                # Extract the name of the content-type
                content_type_name = os.path.basename(os.path.dirname(os.path.dirname(subdir)))
    
                # Define the path to the new schema.json file
                new_file_path = os.path.join(source_dir, content_type_name, "content-types", content_type_name, file)
    
                # Check if the new schema.json file exists
                if os.path.exists(new_file_path):
                    # Replace the current schema.json file with the new one
                    shutil.copy(new_file_path, current_file_path)
                    print(f"Replaced {current_file_path} with {new_file_path}")
    

    If you have any further Questions, I’m happy to answer them.

    EDIT: Made the issue and what has to be done a little bit clearer.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search