英文:
MedusaJs with strapi default command run error - ApplicationError: The type is required
问题
I am setting up medusaJS with Strapi by default command. 我正在使用默认命令来设置medusaJS和Strapi。
I did setup Redis, medusa cli, was using Node version 16,18. However, I got this issue. 我已经设置了Redis、medusa cli,并使用了Node版本16、18。但是,我遇到了这个问题。
Could you please help me? 你能帮助我吗?
Thanks. 谢谢。
英文:
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.
> strapi-medusa@0.1.0 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
答案1
得分: 2
如其他人所建议,与 Medusa 源代码本身无关。您遇到的问题是模式中缺少类型字段。
代码的这部分,您从中获取错误的地方,解析了 src/api/[content-type-name]/content-types/[content-type-name] 下的 content-types 文件夹中的 schema.json 文件。注意到您选择的特定模板的这些 schema.json 文件中,并非所有属性都有一个类型字段。
Strapi v4 在其模式结构中引入了重大更改。一些迁移到 v4 的迁移可以自动应用,就像发生在 shahednasser/strapi-medusa-template 中一样。但有一些是手动的,这些迁移未应用于该目录。您需要将模式文件中的其余更改迁移到 Strapi v4 的新格式,然后一切都应该正常工作。
仅供参考,以下是 v3 和 v4 中 payment-provider content-type 的片段:
v3:
"regions": {
"via": "payment_providers",
"collection": "region"
}
v4:
"regions": {
"type": "relation",
"relation": "manyToMany",
"target": "api::region.region",
"inversedBy": "payment_providers"
}
一些人已经这样做了,所以我从 此 存储库中获取了模式文件,并编写了一个简单的 Python 脚本,将所有文件从该存储库替换为 shahednasser 模板中的文件:
import os
import shutil
# 定义新 schema.json 文件所在的源目录
source_dir = "src/api"
# 定义应替换的现有 schema.json 文件所在的目标目录
target_dir = "strapi-medusa/src/api"
# 遍历目标目录中的所有子目录
for subdir, dirs, files in os.walk(target_dir):
for file in files:
# 检查当前文件是否为 schema.json 文件
if file == "schema.json":
# 定义当前 schema.json 文件的路径
current_file_path = os.path.join(subdir, file)
# 提取 content-type 的名称
content_type_name = os.path.basename(os.path.dirname(os.path.dirname(subdir)))
# 定义新 schema.json 文件的路径
new_file_path = os.path.join(source_dir, content_type_name, "content-types", content_type_name, file)
# 检查新 schema.json 文件是否存在
if os.path.exists(new_file_path):
# 用新文件替换当前 schema.json 文件
shutil.copy(new_file_path, current_file_path)
print(f"Replaced {current_file_path} with {new_file_path}")
如果您有任何进一步的问题,我很乐意回答。
英文:
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.
答案2
得分: 0
We cannot resolve it from our side because it is from the source code of Medusa.
我們無法從我們這一邊解決它,因為它來自Medusa的源代碼。
I format the data by a function, then import the result into postgres DB.
我通過一個函數對數據進行格式化,然後將結果導入到Postgres數據庫中。
So, if you need more help please inform me.
所以,如果您需要更多幫助,請通知我。
英文:
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.
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-html -->
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));
<!-- end snippet -->
So, if you need more help please inform me.
Best wish
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论