Skip to content

Cannot read property 'get' of undefined – file.pragmas.get("jsximportsource") in getJSXImplicitImportBaseΒ #43373

@joshuaellis

Description

@joshuaellis

Bug Report

πŸ”Ž Search Terms

  • Typescript Cannot read property 'get' of undefined
  • TypeError: Cannot read property 'get' of undefined
  • Typescript getJSXImplicitImportBase fails in CI

πŸ•— Version & Regression Information

4.2.3 & nightly

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about everything but it hasn't been covered.

⏯ Playground Link

This is happening on the CI only. And sometimes when I change the jsx property of my tsconfig.json but it's very intermittent.

πŸ’» Code

The codebase is react-spring and you can see the CI failing in this PR pmndrs/react-spring#1361.
Link to specific message here

This is the test I'm currently running locally using https://github.com/nektos/act to debug locally the action as it only fails consistently in the CI. Running tests locally do not throw an error.

describe('animated component', () => {
  it('should pass ', () => {
    expect(true).toBeTruthy()
  })
})

My TSConfig for the web package is:

{
  "include": ["./src"],
  "compilerOptions": {
    "baseUrl": ".",
    "forceConsistentCasingInFileNames": true,
    "jsx": "react",
    "lib": ["dom", "es2017"],
    "moduleResolution": "node",
    "noEmitOnError": true,
    "noFallthroughCasesInSwitch": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "preserveSymlinks": true,
    "sourceMap": true,
    "strict": true,
    "esModuleInterop": true,
    "target": "esnext"
  }
}

πŸ™ Actual behavior

The test only fail when using a CI either in github or using https://github.com/nektos/act

As seen in the error message from the CI:

TypeError: Cannot read property 'get' of undefined

      at Object.getJSXImplicitImportBase (../../node_modules/typescript/lib/typescript.js:19174:95)
      at transformSourceFile (../../node_modules/typescript/lib/typescript.js:88621:51)
      at transformSourceFileOrBundle (../../node_modules/typescript/lib/typescript.js:82537:57)
      at transformation (../../node_modules/typescript/lib/typescript.js:100187:24)
      at transformRoot (../../node_modules/typescript/lib/typescript.js:100214:82)
      at Object.transformNodes (../../node_modules/typescript/lib/typescript.js:100198:78)
      at emitJsFileOrBundle (../../node_modules/typescript/lib/typescript.js:100849:32)
      at emitSourceFileOrBundle (../../node_modules/typescript/lib/typescript.js:100796:13)
      at forEachEmittedFile (../../node_modules/typescript/lib/typescript.js:100517:34)
      at Object.emitFiles (../../node_modules/typescript/lib/typescript.js:100776:9)

Looking closer at the error message and looking at the src it looks like this function is throwing:

function getJSXImplicitImportBase(compilerOptions, file) {
        var jsxImportSourcePragmas = file === null || file === void 0 ? void 0 : file.pragmas.get("jsximportsource");
        var jsxImportSourcePragma = ts.isArray(jsxImportSourcePragmas) ? jsxImportSourcePragmas[0] : jsxImportSourcePragmas;
        return compilerOptions.jsx === 4 /* ReactJSX */ ||
            compilerOptions.jsx === 5 /* ReactJSXDev */ ||
            compilerOptions.jsxImportSource ||
            jsxImportSourcePragma ?
            (jsxImportSourcePragma === null || jsxImportSourcePragma === void 0 ? void 0 : jsxImportSourcePragma.arguments.factory) || compilerOptions.jsxImportSource || "react" :
            undefined;
    }

I presume it's specifically having an issue with file.pragmas.

It's really difficult to debug this in the CI and I'm really hoping its something really simple that I'm overlooking. I asked for help in the Discord but I think this is a bit too wild. Please let me know if there's any more information I can give to help.

πŸ™‚ Expected behavior

It should pass in the CI.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScript

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions