TS2307 when importing Apex module in TypeScript LWC – @salesforce/apex/TodoController.getTodos

16 views
Skip to first unread message

akippiko

unread,
May 19, 2025, 11:43:43 PMMay 19
to Illuminated Cloud Q&A

I'm building a TypeScript-based LWC project using WebStorm + Illuminated Cloud.

I was implementing a basic todoApp.ts component, and added a line to call an Apex class method:

```
// todoApp.ts
import { LightningElement, track, wire } from 'lwc';
import getTodos from '@salesforce/apex/TodoController.getTodos';

export default class TodoApp extends LightningElement {
  @track todos = [];

  @wire(getTodos)
  wiredTodos({ data, error }) {
    if (data) {
      this.todos = data;
    } else {
      console.error(error);
    }
  }
}
```

As soon as I added the import getTodos from '@salesforce/apex/...'; line, I started getting this error:

```
TS2307: Cannot find module '@salesforce/apex/TodoController.getTodos' or its corresponding type declarations.
```

As a result, push metadata button won't deploy the component.


✅ What I tried so far:

0. Removed deprecated @types/eslint__js:

At one point, I had a TS error related to missing types for 'eslint__js', which was being pulled in indirectly by one of the ESLint-related packages.
After some research, I removed @types/eslint__js as it is deprecated and unnecessary when using @eslint/js, like this:

```

npm uninstall @types/eslint__js

```

1. Created a manual type declaration in types/lwc-apex.d.ts:

```
declare module '@salesforce/apex/*' {
  const fn: (...args: any[]) => Promise<any>;
  export default fn;
}
```

2. My tsconfig.json (relevant parts):

```

{
  "compilerOptions": {
    "target": "ES2020",
    "module": "ESNext",
    "moduleResolution": "Node",
    "baseUrl": ".",
    "paths": {
      "lwc": ["node_modules/@lwc/types"]
    },
    "typeRoots": [
      "./node_modules/@types",
      "./node_modules/@lwc/types",
      "./types"
    ]
  },
  "include": [
    "force-app/main/default/lwc/**/*",
    "types/**/*"
  ]
}

```

3. Installed all the relevant packages:

```
npm install --save-dev @lwc/types @typescript-eslint/parser @typescript-eslint/eslint-plugin
```


Scott

unread,
May 20, 2025, 9:17:19 AMMay 20
to Illuminated Cloud Q&A, akip...@gmail.com

Hi. Illuminated Cloud should be maintaining stubs for @AuraEnabled Apex symbols — and other LWC-importable Salesforce metadata — under <projectDir>/.illuminatedCloud/lwc/types. For @AuraEnabled Apex symbols, they would be found under .../lwc/types/apex/<ClassName>Exports.d.ts, e.g.:

// DO NOT EDIT: This file is managed by Illuminated Cloud. Any external changes will be discarded. declare module "@salesforce/apex/ExpenseController.getExpense" { export default function getExpense(): Promise<Expense__c>; } declare module "@salesforce/apex/ExpenseController.getExpenses" { export default function getExpenses(): Promise<Expense__c[]>; } declare module "@salesforce/apex/ExpenseController.saveExpense" { export default function saveExpense(params: {expense: Expense__c}): Promise<Expense__c>; }

If you’re not seeing those, please make sure that you’re on the latest version of Illuminated Cloud and, if so and you still see the issue, please log a bug in the public issue tracker with your idea.log file(s) for review.

Regards,
Scott Wells

akippiko

unread,
May 20, 2025, 10:04:40 AMMay 20
to Illuminated Cloud Q&A, Scott, akippiko
Thank you for your response.

I checked my project, but unfortunately, the .d.ts typings for @AuraEnabled Apex classes are not being generated under `.illuminatedCloud/lwc/types/apex` as expected.
a.png
I've confirmed that I'm using the latest version of Illuminated Cloud and tried various troubleshooting steps, including reindexing and clearing caches, but the issue persists.

To help investigate further, I have created a new issue on your public issue tracker and attached the `idea.log` file there.

Here is the link to the issue:
https://bitbucket.org/RoseSilverSoftware/illuminatedcloud/issues/2794/lwc-apex-typings-dts-are-not-being

Please let me know if you need any additional information.

regards,  

2025年5月20日火曜日 22:17:19 UTC+9 Scott:
Reply all
Reply to author
Forward
0 new messages