Import / export may only appear at top level issue

HI

Can anyone help me ? im getting the Import / export may only appear at top level error on this code where i marked error here

Thanks

//Meal 1 Nutrient value populate from old diet
return wixData.query(“MyFoods”)
.eq(“foodType”,$w(‘#food1Dropdown’).value)
.find()
.then( (results) => {
let items = results.items;
let item = items[0];
let protein = item.protein
let carbohydrates = item.carbs
let fat = item.fat;
let calories = item.calories;
$w(‘#protein1Text’).text = item.protein.toString();
$w(‘#carbohydrate1Text’).text = item.carbs.toString();
$w(‘#fat1Text’).text = item.fat.toString();
$w(‘#calories1Text’).text = item.calories.toString();
console.log(protein,carbohydrates,fat,calories);
} )
. catch ( (err) => {
let errorMsg = err;
console.log(errorMsg);

return wixData.query(“MyFoods”)
.eq(“foodType”,$w(‘#food2Dropdown’).value)
.find()
.then( (results) => {
let items = results.items;
let item = items[0];
let protein = item.protein
let carbohydrates = item.carbs
let fat = item.fat;
let calories = item.calories;
$w(‘#protein2Text’).text = item.protein.toString();
$w(‘#carbohydrate2Text’).text = item.carbs.toString();
$w(‘#fat2Text’).text = item.fat.toString();
$w(‘#calories2Text’).text = item.calories.toString();
console.log(protein,carbohydrates,fat,calories);
} )
. catch ( (err) => {
let errorMsg = err;
console.log(errorMsg);
})
}
);

//Meal 1 Dropdown events
ERROR HERE - export function food1Dropdown_change(event) {
return wixData.query(“MyFoods”)
.eq(“foodType”,$w(‘#food1Dropdown’).value)
.find()
.then( (results) => {
let items = results.items;
let item = items[0];
let measurement = item.measurement;
let protein = item.protein
let carbohydrates = item.carbs
let fat = item.fat;
let calories = item.calories;
$w(“#qty1Dropdown”).enable();
$w(‘#measurement1Text’).value = item.measurement;
if ( $w(“#measurement1Text”).hidden ) {
$w(“#measurement1Text”).show();
}
$w(‘#protein1Text’).text = item.protein.toString();
$w(‘#carbohydrate1Text’).text = item.carbs.toString();
$w(‘#fat1Text’).text = item.fat.toString();
$w(‘#calories1Text’).text = item.calories.toString();
console.log(measurement,protein,carbohydrates,fat,calories);
} )
. catch ( (err) => {
let errorMsg = err;
console.log(errorMsg);
})
}

I’m trying to solve the same problem

  • The whole code used here needs to be shown and not just parts of it - we do not know what is above the return at the top of the original code, so we can’t tell what else has been used;

  • Have you got the imports at the top of your page;

  • Have you got a onReady for the page in your code;

  • Have you got the correct curly brackets and parentheses all setup in the correct places for your code?

This is an old post from last year and being closed, please add a new post if you still require help with it with a link to refer back to it if needed - along with all your code used so that we can;t just use guesswork.