Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NodeJS thinks I am duplicating parameter names when I am not

Thanks for looking at my question.

In this javascript initialization code, on line 94, I am getting a syntax error: "Duplicate parameter name not allowed in this context". However, I am not duplicating any parameters. All of my functions' parameters names are unique within their scope.

The repository is at https://github.com/allenchan3/foodproject/blob/c3442a3b8542e1f9cbcc5f3f78175765a292dd9a, and the script in question is at https://github.com/allenchan3/foodproject/blob/c3442a3b8542e1f9cbcc5f3f78175765a292dd9a/server/config/initialize.js. The error is appearing on the function call to create_menu_items. I carefully inspected this file for duplicate parameter names but found none. I tried changing the names of each of the 3 declared variables in the main function, along with changing the names of the parameters. Nothing seems to get rid of the syntax error, which is preventing my function from executing.

async function create_menu_items(filenames, directory, cat_names_to_ids) {
    /// stuff
}
async function main() {
    await create_menu_items(menu_item_filenames, menu_item_dir, categories_name_to_id);
}


[skyler@laptop server]$ npm start
[.....snip.....]
(node:6571) UnhandledPromiseRejectionWarning: SyntaxError: Duplicate parameter name not allowed in this context

As mentioned, this error keeps appearing and the function create_menu_items doesn't run, even though I think it should, because none of the parameters appear to be in conflict with anything.

Thanks again for taking a look.

like image 233
Skyler827 Avatar asked Jan 21 '26 10:01

Skyler827


2 Answers

Here's your problem

objects.reduce((prev_items,curr_items_obj,_,_)=>{
                                          ^ ^

It seems that you wanted to omit optional parameters this way, but you should just skip them like this:

objects.reduce((prev_items,curr_items_obj)=>{
like image 117
Nurbol Alpysbayev Avatar answered Jan 22 '26 23:01

Nurbol Alpysbayev


If you really care to use _ for omited parameters, name the other one as __ (double underscore) to avoid duplicate parameter error, as such:

objects.reduce((prev_items,curr_items_obj,_,__)=>{
like image 41
Ante Avatar answered Jan 23 '26 00:01

Ante



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!