Skip to content

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

Open
@hambergerpls

Description

@hambergerpls

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.

Activity

mrmckeb

mrmckeb commented on Oct 10, 2024

@mrmckeb
Owner

Hi @hambergerpls, are you able to provide a reproduction? I can then dig into the issue and see if it's a configuration problem or something we can fix within the plugin.

modified the milestone: v6.0.0 on Oct 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Typescript 5.4.5: Cannot read properties of undefined (reading 'getSourceFile') · Issue #265 · mrmckeb/typescript-plugin-css-modules