TypeScript: TypeError: Cannot read property 'flags' of undefined when running TSC

Hi! πŸ‘‹

Firstly, thanks for your work on this project! πŸ™‚

Today I used patch-package to patch typescript@4.6.2 for the project I’m working on.

We encountered this when upgrading from typescript 4.1.3 to a higher version. Here is the diff that solved my problem:

diff --git a/node_modules/typescript/lib/tsc.js b/node_modules/typescript/lib/tsc.js
index 7704b1a..65cf863 100644
--- a/node_modules/typescript/lib/tsc.js
+++ b/node_modules/typescript/lib/tsc.js
@@ -71362,8 +71362,9 @@ var ts;
             if (!symbol) {
                 return false;
             }
+            console.log(symbol)
             var target = getExportSymbolOfValueSymbolIfExported(resolveAlias(symbol));
-            if (target === unknownSymbol) {
+            if (!target || target === unknownSymbol) {
                 return true;
             }
             return !!(target.flags & 111551) &&

This issue body was partially generated by patch-package.

Without this patch, I get this:

> tsc -p tsconfig.build.json

/home/capaj/work-repos/secret-project/backend/node_modules/typescript/lib/tsc.js:95304
                throw e;
                ^

TypeError: Cannot read property 'flags' of undefined
    at isAliasResolvedToValue (/home/capaj/work-repos/secret-project/backend/node_modules/typescript/lib/tsc.js:71369:30)
    at isValueAliasDeclaration (/home/capaj/work-repos/secret-project/backend/node_modules/typescript/lib/tsc.js:71341:40)
    at Object.isValueAliasDeclaration (/home/capaj/work-repos/secret-project/backend/node_modules/typescript/lib/tsc.js:71675:35)
    at visitExportSpecifier (/home/capaj/work-repos/secret-project/backend/node_modules/typescript/lib/tsc.js:76896:49)
    at Object.visitNodes (/home/capaj/work-repos/secret-project/backend/node_modules/typescript/lib/tsc.js:73579:48)
    at visitNamedExports (/home/capaj/work-repos/secret-project/backend/node_modules/typescript/lib/tsc.js:76886:31)
    at visitNamedExportBindings (/home/capaj/work-repos/secret-project/backend/node_modules/typescript/lib/tsc.js:76893:79)
    at /home/capaj/work-repos/secret-project/backend/node_modules/typescript/lib/tsc.js:76880:93
    at Object.visitNode (/home/capaj/work-repos/secret-project/backend/node_modules/typescript/lib/tsc.js:73540:23)
    at visitExportDeclaration (/home/capaj/work-repos/secret-project/backend/node_modules/typescript/lib/tsc.js:76880:35)

I have logged the symbol just before the crash and that prints out like this:

<ref *1> Symbol {
  flags: 2097152,
  escapedName: 'staticServerApi',
  declarations: [
    Node {
      pos: 8,
      end: 35,
      kind: 274,
      id: 0,
      flags: 32768,
      modifierFlagsCache: 536870912,
      transformFlags: 0,
      parent: [Node],
      original: undefined,
      isTypeOnly: false,
      propertyName: [Identifier],
      name: [Identifier],
      symbol: [Circular *1]
    }
  ],
  valueDeclaration: undefined,
  id: 17655,
  mergeId: undefined,
  parent: <ref *2> Symbol {
    flags: 512,
    escapedName: '"/home/capaj/work-repos/momence/ribbon-backend/routes/index"',
    declarations: [ [Node] ],
    valueDeclaration: Node {
      pos: 0,
      end: 2495,
      kind: 303,
      id: 61756,
      flags: 0,
      modifierFlagsCache: 0,
      transformFlags: 0,
      parent: undefined,
      original: undefined,
      statements: [Array],
      endOfFileToken: [Token],
      fileName: '/home/capaj/work-repos/momence/ribbon-backend/routes/index.ts',
      text: "export { default as staticServerApi } from './static-server-api'\n" +
        "export { default as hostLandingPage } from './host-landing-page'\n" +
        "export { default as hostDashboardAnnouncements } from './host-dashboard/announcements'\n" +
        "export { default as hostDashboardSms } from './host-dashboard/sms'\n" +
        "export { default as hostDashboardSmsMessaging } from './host-dashboard/sms/messaging'\n" +
        "export { default as hostDashboardBilling } from './host-dashboard/billing'\n" +
        "export { default as hostDashboardOndemandVideoOptimizations } from './host-dashboard/ondemand-video-optimizations'\n" +
        '\n' +
        "export { adminRoutes } from './admin'\n" +
        "export { apiRoutes } from './api'\n" +
        "export { hostDashboardCrm } from './host-dashboard/crm'\n" +
        "export { publicApiRoutes } from './public-api'\n" +
        "export { hostDasboardRoutes } from './host-dashboard/dashboard'\n" +
        "export { hostDashboardOndemandLibraryRoutes } from './host-dashboard/ondemand-library'\n" +
        "export { authRoutes } from './auth'\n" +
        "export { onDemandRoutes } from './ondemand-plugin'\n" +
        "export { awsS3OperationsRoutes } from './aws-s3-operations'\n" +
        "export { feedRoutes } from './feed'\n" +
        "export { pluginRoutes } from './plugin'\n" +
        "export { studioRoutes } from './host-dashboard/studio'\n" +
        "export { discountCodesRoutes } from './host-dashboard/discount-codes'\n" +
        "export { adminPanelRoutes } from './admin/admin-panel'\n" +
        "export { hostDashboardRoutes } from './host-dashboard'\n" +
        "export { memberPortalRoutes } from './member-portal'\n" +
        "export { integrationsRoutes } from './integrations'\n" +
        "export { pollsRoutes } from './poll'\n" +
        "export { kioskRoutes } from './kiosk'\n" +
        "export { hostDashboardAppointmentsRoutes } from './host-dashboard/appointments'\n" +
        "export { webhooksRoutes } from './webhooks'\n" +
        "export { pluginAppointmentsRoutes } from './plugin/appointments'\n" +
        "export { mobileRoutes } from './mobile'\n" +
        "export { docsRoutes } from './docs'\n" +
        "export { landingPageRoutes } from './landing-page'\n" +
        "export { memberPortalAppointmentsRoutes as memberDashboardAppointmentsRoutes } from './member-portal/appointments'\n" +
        "export { hostDashboardTransactionalTemplatesRoutes } from './host-dashboard/transactionalMessages'\n" +
        "export { hostDashboardMarketingMessagesRoutes } from './host-dashboard/marketingMessages'\n" +
        "export { hostDashboardAutomationRoutes } from './host-dashboard/automations'\n" +
        "export { hostDashboardIntegrationsRoutes } from './host-dashboard/integrations'\n" +
        "export { hostDashboardPosRoutes } from './host-dashboard/pos'\n" +
        "export { hostDashboardApplicationAddonsRoutes } from './host-dashboard/applicationAddons'\n" +
        "export { signUpRoutes } from './sign-up'\n",
      languageVersion: 7,
      languageVariant: 0,
      scriptKind: 3,
      isDeclarationFile: false,
      hasNoDefaultLib: false,
      externalModuleIndicator: [Node],
      bindDiagnostics: [],
      bindSuggestionDiagnostics: undefined,
      pragmas: Map(0) {},
      checkJsDirective: undefined,
      referencedFiles: [],
      typeReferenceDirectives: [],
      libReferenceDirectives: [],
      amdDependencies: [],
      commentDirectives: undefined,
      nodeCount: 210,
      identifierCount: 48,
      identifiers: [Map],
      parseDiagnostics: [],
      version: '3a265a8b2eeff309dcecdda50184400dd25195aedd3eee988ab2ff8311622d5a',
      path: '/home/capaj/work-repos/momence/ribbon-backend/routes/index.ts',
      resolvedPath: '/home/capaj/work-repos/momence/ribbon-backend/routes/index.ts',
      originalFileName: '/home/capaj/work-repos/momence/ribbon-backend/routes/index.ts',
      impliedNodeFormat: undefined,
      imports: [Array],
      moduleAugmentations: [],
      ambientModuleNames: [],
      resolvedModules: [Object],
      symbol: [Circular *2],
      locals: Map(0) {},
      endFlowNode: [Object],
      symbolCount: 41,
      classifiableNames: [Set]
    },
    id: 17654,
    mergeId: undefined,
    parent: undefined,
    exports: Map(40) {
      'staticServerApi' => [Circular *1],
      'hostLandingPage' => [Symbol],
      'hostDashboardAnnouncements' => [Symbol],
      'hostDashboardSms' => [Symbol],
      'hostDashboardSmsMessaging' => [Symbol],
      'hostDashboardBilling' => [Symbol],
      'hostDashboardOndemandVideoOptimizations' => [Symbol],
      'adminRoutes' => [Symbol],
      'apiRoutes' => [Symbol],
      'hostDashboardCrm' => [Symbol],
      'publicApiRoutes' => [Symbol],
      'hostDasboardRoutes' => [Symbol],
      'hostDashboardOndemandLibraryRoutes' => [Symbol],
      'authRoutes' => [Symbol],
      'onDemandRoutes' => [Symbol],
      'awsS3OperationsRoutes' => [Symbol],
      'feedRoutes' => [Symbol],
      'pluginRoutes' => [Symbol],
      'studioRoutes' => [Symbol],
      'discountCodesRoutes' => [Symbol],
      'adminPanelRoutes' => [Symbol],
      'hostDashboardRoutes' => [Symbol],
      'memberPortalRoutes' => [Symbol],
      'integrationsRoutes' => [Symbol],
      'pollsRoutes' => [Symbol],
      'kioskRoutes' => [Symbol],
      'hostDashboardAppointmentsRoutes' => [Symbol],
      'webhooksRoutes' => [Symbol],
      'pluginAppointmentsRoutes' => [Symbol],
      'mobileRoutes' => [Symbol],
      'docsRoutes' => [Symbol],
      'landingPageRoutes' => [Symbol],
      'memberDashboardAppointmentsRoutes' => [Symbol],
      'hostDashboardTransactionalTemplatesRoutes' => [Symbol],
      'hostDashboardMarketingMessagesRoutes' => [Symbol],
      'hostDashboardAutomationRoutes' => [Symbol],
      'hostDashboardIntegrationsRoutes' => [Symbol],
      'hostDashboardPosRoutes' => [Symbol],
      'hostDashboardApplicationAddonsRoutes' => [Symbol],
      'signUpRoutes' => [Symbol]
    }
  }
}

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 8
  • Comments: 15 (3 by maintainers)

Most upvoted comments

Same issue πŸ˜•

Sorry this took so long @andrewbranch, hope this helps. If it’s useful, I’m using yarn-3.1.1. I just tried again today, and still getting the error in the same package.

{
  "name": "@my-project/library-web",
  "version": "2.0.25",
  "main": "./dist/index.js",
  "module": "./index.ts",
  "types": "./dist/index.d.ts",
  "files": [
    "dist/**/*"
  ],
  "scripts": {
    "build": "yarn tsc -b tsconfig.build.json",
    "dev": "yarn tsc -b -w tsconfig.json",
    "upgrade:version": "semantic-release",
    "update": "ncu --configFilePath ../../.config"
  },
  "dependencies": {
    "@my-project/library-types": "^2.0.21",
    "@sentry/browser": "^6.19.3",
    "@types/node": "^17.0.23",
    "@yarnpkg/pnpify": "^3.1.1",
    "analytics-node": "^6.0.0",
    "axios": "^0.26.1",
    "btoa": "^1.2.1",
    "cookie": "^0.4.2",
    "lodash": "^4.17.21",
    "mongoose": "6.2.9",
    "next": "12.1.4",
    "react": "^18.0.0",
    "react-dom": "^18.0.0",
    "react-is": "^18.0.0",
    "remove-markdown": "^0.3.0",
    "socket.io-client": "^4.4.1",
    "styled-components": "5.3.5",
    "swr": "^1.2.2",
    "universal-cookie": "^4.0.4"
  },
  "devDependencies": {
    "@semantic-release/git": "^10.0.1",
    "@semantic-release/gitlab": "^8.0.2",
    "@svgr/webpack": "^6.2.1",
    "@types/analytics-node": "^3.1.7",
    "@types/jest": "^27.4.1",
    "@types/react-is": "^17.0.3",
    "semantic-release": "19.0.2",
    "semantic-release-monorepo": "^7.0.5",
    "typescript": "4.6.3"
  }
}

I had created a subrepo within my repo. My repo normally works, but with the subrepo it triggered the same error. The subrepo is the following: https://github.com/brettle/jsdoc-to-typescript-declaration

However, the error comes from the node modules of the top-level repo, not the inner one.

I deleted the subrepo and everything works correctly now.

I get the same error.