created a propper fix (I think, not fimiliar with the code):
replace
if recipe.normal then
replaceingredients(recipe.normal.ingredients)
replaceingredients(recipe.expensive.ingredients)
else
replaceingredients(recipe.ingredients)
end
with
if recipe.normal then
replaceingredients(recipe.normal.ingredients)
end
if recipe.expensive then
replaceingredients(recipe.expensive.ingredients)
end
if not (recipe.normal or recipe.expensive) then
replaceingredients(recipe.ingredients)
end
This basically just adds nil checks around all the calls as it should have been to begin with.
EDIT:
to be clear this just makes sure it doesn't crash, this might not be the intended behavior.
EDIT2:
after reading https://wiki.factorio.com/Prototype/Recipe#Recipe_data I updated the code to match their description.