Repository: facebook/jest
File: packages/jest-config/src/readConfigFileAndSetRootDir.ts (TypeScript)

Code before:
    configPath.endsWith(JEST_CONFIG_EXT_TS) ||
    configPath.endsWith(JEST_CONFIG_EXT_CTS);
  const isJSON = configPath.endsWith(JEST_CONFIG_EXT_JSON);
  let configObject;

  try {
    if (isTS) {
      // @ts-expect-error: type assertion can be removed once @types/node is updated to 23 https://nodejs.org/api/process.html#processfeaturestypescript
      if (process.features.typescript) {
        try {
          // try native node TypeScript support first
          configObject = await requireOrImportModule<any>(configPath);
        } catch (error) {
          if (
            !(
              error instanceof SyntaxError &&
              // likely ESM in a file interpreted as CJS, which means it needs to be
              // transpiled - we ignore the error and try to load it with a loader
              error.message.match(/Unexpected token '(export|import)'/)
            )
          ) {
            throw error;
          }
        }
      }
      // fall back to `ts-node` etc. if this cannot be natively parsed/executed
      if (!configObject) {
        configObject = await loadTSConfigFile(configPath);
      }
    } else if (isJSON) {
      const fileContent = fs.readFileSync(configPath, 'utf8');
      configObject = parseJson(stripJsonComments(fileContent), configPath);
    } else {
      configObject = await requireOrImportModule<any>(configPath);
    }
  } catch (error) {
    if (isTS) {
      throw new Error(
        `Jest: Failed to parse the TypeScript config file ${configPath}\n` +
          `  ${error}`,
      );
    }

    throw error;
  }

  if (configPath.endsWith(PACKAGE_JSON)) {
    // Event if there's no "jest" property in package.json we will still use
    // an empty object.
    configObject = configObject.jest || {};
  }

Review comment (suggestion):
```suggestion
      // Fall back to `ts-node` etc. if this cannot be natively parsed/executed.
```

Code after:
    configPath.endsWith(JEST_CONFIG_EXT_TS) ||
    configPath.endsWith(JEST_CONFIG_EXT_CTS);
  const isJSON = configPath.endsWith(JEST_CONFIG_EXT_JSON);
  let configObject;

  try {
    if (isTS) {
      // @ts-expect-error: Type assertion can be removed once @types/node is updated to 23 https://nodejs.org/api/process.html#processfeaturestypescript
      if (process.features.typescript) {
        try {
          // Try native node TypeScript support first.
          configObject = await requireOrImportModule<any>(configPath);
        } catch (error) {
          if (
            !(
              error instanceof SyntaxError &&
              // Likely ESM in a file interpreted as CJS, which means it needs to be
              // compiled. We ignore the error and try to load it with a loader.
              error.message.match(/Unexpected token '(export|import)'/)
            )
          ) {
            throw error;
          }
        }
      }
      // Fall back to `ts-node` etc. if this cannot be natively parsed/executed.
      if (!configObject) {
        configObject = await loadTSConfigFile(configPath);
      }
    } else if (isJSON) {
      const fileContent = fs.readFileSync(configPath, 'utf8');
      configObject = parseJson(stripJsonComments(fileContent), configPath);
    } else {
      configObject = await requireOrImportModule<any>(configPath);
    }
  } catch (error) {
    if (isTS) {
      throw new Error(
        `Jest: Failed to parse the TypeScript config file ${configPath}\n` +
          `  ${error}`,
      );
    }

    throw error;
  }

  if (configPath.endsWith(PACKAGE_JSON)) {
    // Event if there's no "jest" property in package.json we will still use
    // an empty object.
    configObject = configObject.jest || {};
  }