emotion-js/emotion · error · Error

Unexpected null when attempting to fix ${context.getFilename

Error message

Unexpected null when attempting to fix ${context.getFilename()} - please file a github issue at ${REPO_URL}

What it means

The jsx-import ESLint rule's autofixer replaces the @jsxImportSource pragma comment; it asserts the comment node it located earlier is non-null when the fix runs. If it's null at fix time (an internal invariant violation), it throws and asks the user to file a GitHub issue.

Source

Thrown at packages/eslint-plugin/src/rules/jsx-import.ts:115

              node,
              messageId: 'cssProp',
              data: { importSource },
              fix(fixer) {
                return fixer.insertTextBefore(
                  sourceCode.ast.body[0],
                  `/** @jsxImportSource ${importSource} */\n`
                )
              }
            })
          } else if (!validJsxImportSource && jsxImportSourcePragmaComment) {
            context.report({
              node,
              messageId: 'cssProp',
              data: { importSource },
              fix(fixer) {
                /* istanbul ignore if */
                if (jsxImportSourcePragmaComment === null) {
                  throw new Error(
                    `Unexpected null when attempting to fix ${context.getFilename()} - please file a github issue at ${REPO_URL}`
                  )
                }

                return fixer.replaceText(
                  jsxImportSourcePragmaComment,
                  `/** @jsxImportSource ${importSource} */`
                )
              }
            })
          }
        }
      }
    }

    return {
      JSXAttribute(node) {
        if (node.name.name !== 'css') {

View on GitHub (pinned to b882bcba85)

Solutions

  1. File a GitHub issue at the emotion repo with the file and ESLint config reproducing it
  2. Temporarily disable the jsx-import rule (or run without --fix) for that file
  3. Update @emotion/eslint-plugin to the latest version in case the bug is fixed
Defensive patterns

Strategy: try-catch

Validate before calling

// no pre-call validation possible; this is an internal invariant of the rule's fixer

Prevention

When it happens

Trigger: Running eslint --fix on JSX code where the rule reported 'cssProp' but the previously captured jsxImportSourcePragmaComment reference became null when the fixer executed.

Common situations: A plugin/rule bug rather than user error — potentially triggered by unusual comment positioning or interactions with other fixing rules between suggestion and fix phases.

Related errors


AI-assisted analysis of emotion-js/emotion@b882bcba85 (2026-09-02). Data as JSON: /api/errors/a3559546f427e0b0. Report an issue: GitHub.