Describe the bug
When gatsby build, the error "Cannot read properties of undefined (reading 'split')" is raised. After investigating, I have narrowed down the issue to the following content type schema:
User content type (from permission-user plugin) has a one-to-one relationship with the Editor content type.
Post content type has a belongs-to relationship with the Editor content type.
Editor content type has a richtext field called bio.
The issue arises when the bio field in the User content type's editor relation is in string format, while the plugin expects it to be in richtext object format.
See these source codes, in the setting above it would be equivalent to extraftFiles(undefined, apiURL), then it causes the error.
if (type === "richtext") {
const extractedFiles = extractFiles(value.data, apiURL);
Noted that the bio field in the Post content type's editor relation is in the correct richtext object format with the following structure:
{
data: string,
medias: Media[],
}
Proof of Concept
I've added several log lines inside the function download-media-files.extractImages().
Part 1
if (value && type) {
// Start of log code.
if (attributeName === "bio") {
console.log("[uid]", uid, "[type]", type, "[value]", value);
}
// End of log code.
if (type === "richtext") {
...
Part 2
if (type === "relation") {
// Start of log code.
console.log("<relation>", "[uid]", uid, "[value]", value, "[target]", attribute.target);
// End of log code.
await extractImages(value, context, attribute.target);
}
The log
The log is as follow, omitting unimportant parts.
<relation> [uid] api::post.post [value] {
bio: {
data: "**Chia-Sheng** is an experienced engineer with a strong background in .NET related technologies, including C#
and Azure. He is proficient in React.js and previously worked with Ruby on Rails. While he's not coding, **Chia-Sheng**
enjoys traveling and playing football.",
medias: []
},
} [target] api::editor.editor
[uid] api::editor.editor [type] richtext [value] {
data: "**Chia-Sheng** is an experienced engineer with a strong background in .NET related technologies, including C#
and Azure. He is proficient in React.js and previously worked with Ruby on Rails. While he's not coding, **Chia-Sheng**
enjoys traveling and playing football.",
medias: []
}
<relation> [uid] plugin::users-permissions.user [value] {
bio: "**Chia-Sheng** is an experienced engineer with a strong background in .NET related technologies, including C#
and Azure. He is proficient in React.js and previously worked with Ruby on Rails. While he's not coding, **Chia-Sheng**
enjoys traveling and playing football.",
} [target] api::editor.editor
[uid] api::editor.editor [type] richtext [value] **Chia-Sheng** is an experienced engineer with a strong background in
.NET related technologies, including C# and Azure. He is proficient in React.js and previously worked with Ruby on
Rails. While he's not coding, **Chia-Sheng** enjoys traveling and playing football.
In the log, we see that the value for the api::post.post relationship is an object with a bio property, where the bio property is itself an object with a data property and a medias property. The data property contains a string value with some biographical information about a person.
On the other hand, the value for the plugin::users-permissions.user relationship is a string containing the same biographical information as the data property in the first schema.
System Info
https://github.com/cschenio/blog
Error Log
This is the log for yarn run build --verbose.
ERROR #11321 API.NODE.EXECUTION
"gatsby-source-strapi" threw an error while running the sourceNodes lifecycle:
Cannot read properties of undefined (reading 'split')
TypeError: Cannot read properties of undefined (reading 'split')
- commonmark.js:9623 Object.parse
[gatsby]/[commonmark]/dist/commonmark.js:9623:27
- download-media-files.js:22 extractFiles
[gatsby]/[gatsby-source-strapi]/dist/download-media-files.js:22:25
- download-media-files.js:135 extractImages
[gatsby]/[gatsby-source-strapi]/dist/download-media-files.js:135:32
- download-media-files.js:186 extractImages
[gatsby]/[gatsby-source-strapi]/dist/download-media-files.js:186:15
- download-media-files.js:215
[gatsby]/[gatsby-source-strapi]/dist/download-media-files.js:215:3
- async Promise.all
not finished source and transform nodes - 4.688s
error Command failed with exit code 1.
Describe the bug
When
gatsby build, the error "Cannot read properties of undefined (reading 'split')" is raised. After investigating, I have narrowed down the issue to the following content type schema:Usercontent type (from permission-user plugin) has a one-to-one relationship with theEditorcontent type.Postcontent type has a belongs-to relationship with theEditorcontent type.Editorcontent type has a richtext field calledbio.The issue arises when the
biofield in theUsercontent type'seditorrelation is in string format, while the plugin expects it to be in richtext object format.See these source codes, in the setting above it would be equivalent to
extraftFiles(undefined, apiURL), then it causes the error.Noted that the
biofield in thePostcontent type'seditorrelation is in the correct richtext object format with the following structure:Proof of Concept
I've added several log lines inside the function
download-media-files.extractImages().Part 1
Part 2
The log
The log is as follow, omitting unimportant parts.
In the log, we see that the value for the
api::post.postrelationship is an object with abioproperty, where thebioproperty is itself an object with adataproperty and amediasproperty. Thedataproperty contains a string value with some biographical information about a person.On the other hand, the value for the
plugin::users-permissions.userrelationship is a string containing the same biographical information as thedataproperty in the first schema.System Info
https://github.com/cschenio/blog
Error Log
This is the log for
yarn run build --verbose.