typescript-plugin-css-modules icon indicating copy to clipboard operation
typescript-plugin-css-modules copied to clipboard

Typescript 5.4.5: Cannot read properties of undefined (reading 'getSourceFile')

Open hambergerpls opened this issue 9 months ago • 1 comments

Describe the bug I'm trying to set up customTemplate option in tsconfig.json.

For testing, I use the following customTemplate.js:

module.exports = (dts, { classes, fileName, logger }) => {
    return dts;
};

But received the following error,

tsserver: 1: <semantic> TypeScript Server Error (5.4.5)
Cannot read properties of undefined (reading 'getSourceFile')                                                                                                                                                                                 TypeError: Cannot read properties of undefined (reading 'getSourceFile')
at ./node_modules/typescript/lib/tsserver.js:146667:82
at mapDefined (./node_modules/typescript/lib/tsserver.js:2680:22)
at Object.getDocumentHighlights (./node_modules/typescript/lib/tsserver.js:146667:33)
at IpcIOSession.getDocumentHighlights (./node_modules/typescript/lib/tsserver.js:186370:61)
at documentHighlights (./node_modules/typescript/lib/tsserver.js:185337:43)
at ./node_modules/typescript/lib/tsserver.js:187569:69
at IpcIOSession.executeWithRequestId (./node_modules/typescript/lib/tsserver.js:187561:14)
at IpcIOSession.executeCommand (./node_modules/typescript/lib/tsserver.js:187569:29)
at IpcIOSession.onMessage (./node_modules/typescript/lib/tsserver.js:187611:51)
at process.<anonymous> (./node_modules/typescript/lib/tsserver.js:189220:14)
at process.emit (node:events:518:28)
at emit (node:internal/child_process:951:14)
at process.processTicksAndRejections (node:internal/process/task_queues:83:21)   

I'm using Neovim as my IDE.

The goal is that I want to add additional variable export for my .module.scss like the following:

   declare module "*.module.scss" {
        const classes: { [key: string]: string };
 	export const code: string;
 	export default classes;
 }

I tried to create this declaration file like custom.d.ts, but the LSP fails to detect code as exported member when I import it:

import styles, { code } from "./test.module.scss"; // Module has no exported member 'code' ...

Since, I couldn't get the custom template to work, I had to modify the source createDtsExports.js and export code from there as a temporary solution.

hambergerpls avatar May 27 '24 07:05 hambergerpls