Why it is forbidden to import several Apex Methods at once in LWC module?

I have Apex Controller Class, say, LWCController and several methods inside of it, let’s say Method1, Method2, Method3, Method4, Method5.

Documentation says that to

Use default import syntax to import an Apex method via the
@salesforce/apex scoped packages.

enter image description here

Default import syntax allows to imports several items from the same module

import { export1 , export2 } from "module-name"; 
import { foo , bar } from "module-name/path/to/specific/un-exported/file"; 
import { export1, export2 as alias2 , [...] } from "module-name"; 
import defaultExport, { export [ , [...] ] } from "module-name";

enter image description here

I am trying to import all of them simultaneously at the same line

import {Method1, Method2, Method3, Method4, Method5 } from '@salesforce/apex/LWCController';

And I receive the following errors

=== Deploy Errors PROJECT PATH  ERRORS    
N/A           [Line: 2, Col: 118] LWC1501: @salesforce/apex modules should have both class and method names.
N/A           LWC1513: @salesforce/apex modules only support default imports.


Looks like here by “default” imports meant only imports which import one item from the module, so I have to use the following workaround.

import Method1 from '@salesforce/apex/LWCController.Method1';
import Method2 from '@salesforce/apex/LWCController.Method2';
import Method3 from '@salesforce/apex/LWCController.Method3';
import Method4 from '@salesforce/apex/LWCController.Method4';
import Method5 from '@salesforce/apex/LWCController.Method5';

which is nasty but the only available workaround.

Source : Link , Question Author : Patlatus , Answer Author : Patlatus

Leave a Comment