{"id":11068,"library":"i18next-scanner-typescript","title":"i18next-scanner TypeScript Transform","description":"i18next-scanner-typescript provides essential TypeScript support for the i18next-scanner tool, enabling it to extract internationalization keys from `.ts` and `.tsx` source files. As of its current stable version `1.2.1`, this package acts as a transform layer, transpiling TypeScript code into JavaScript internally before `i18next-scanner` processes it. This ensures that the scanner can correctly identify `t()` calls and `<Trans>` components in modern TypeScript applications without requiring a separate pre-build step. It is an active part of the `i18next` ecosystem, maintained to ensure compatibility with both `i18next-scanner` and contemporary TypeScript versions, currently requiring `typescript@5.x` as a peer dependency. Its primary differentiator is simplifying the integration of i18n scanning into TypeScript-based projects by handling the necessary transpilation transparently.","status":"active","version":"1.2.1","language":"javascript","source_language":"en","source_url":"ssh://git@github.com/nucleartux/i18next-scanner-typescript","tags":["javascript"],"install":[{"cmd":"npm install i18next-scanner-typescript","lang":"bash","label":"npm"},{"cmd":"yarn add i18next-scanner-typescript","lang":"bash","label":"yarn"},{"cmd":"pnpm add i18next-scanner-typescript","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required for TypeScript transpilation within the transform. Must be version 5.x.","package":"typescript","optional":false}],"imports":[{"note":"The transform is designed to be consumed in CommonJS configuration files for i18next-scanner. Direct ESM imports are not typically supported for config files.","wrong":"import typescriptTransform from 'i18next-scanner-typescript';","symbol":"typescriptTransform","correct":"const typescriptTransform = require('i18next-scanner-typescript');"}],"quickstart":{"code":"const typescriptTransform = require('i18next-scanner-typescript');\nconst path = require('path');\n\nmodule.exports = {\n  input: ['src/**/*.{js,jsx,ts,tsx}', '!src/**/*.spec.{js,jsx,ts,tsx}'],\n  output: path.join(__dirname, 'public/locales/{{lng}}/translation.json'),\n  options: {\n    debug: true,\n    sort: true,\n    lngs: ['en', 'fr'],\n    defaultValue: (lng, namespace, key) => key,\n    resource: {\n      loadPath: path.join(__dirname, 'public/locales/{{lng}}/{{ns}}.json'),\n      savePath: path.join(__dirname, 'public/locales/{{lng}}/{{ns}}.json'),\n      jsonIndent: 2,\n    },\n    func: {\n      extensions: ['.js', '.jsx'], // Important: Only list JS/JSX extensions here\n      list: ['i18next.t', 't'],\n    },\n    trans: {\n      extensions: ['.js', '.jsx'], // Important: Only list JS/JSX extensions here\n      component: 'Trans',\n    },\n  },\n  transform: typescriptTransform(\n    {\n      extensions: ['.ts', '.tsx'], // List TS/TSX extensions for the transform itself\n      tsOptions: {\n        target: 'es2017',\n        jsx: 'react',\n      },\n    },\n    function customTransform(outputText, file, enc, done) {\n      // `this` context here is the i18next-scanner parser instance\n      // Access parsing functions via `this.parseFuncFromString`, etc.\n      this.parser.parseTransFromString(outputText);\n      this.parser.parseFuncFromString(outputText);\n      done();\n    }\n  ),\n};","lang":"javascript","description":"This configuration sets up `i18next-scanner` to process TypeScript and TSX files using the `i18next-scanner-typescript` transform. It demonstrates how to specify the TS/TSX file extensions for the transform while correctly excluding them from the scanner's primary `func` and `trans` options. The custom transform function provides access to `i18next-scanner`'s internal parser to process the transpiled output. To run this, first install `i18next-scanner`, `i18next-scanner-typescript`, and `typescript` as dev dependencies. Create an example `src/App.tsx` file with i18n keys (e.g., `<Trans>Hello</Trans>` or `t('key')`). Then, execute `npx i18next-scanner --config i18next-scanner.config.js` to extract keys."},"warnings":[{"fix":"Ensure `options.func.extensions` and `options.trans.extensions` only contain `.js`, `.jsx`, or similar JavaScript extensions. Configure the TS/TSX extensions solely within the `typescriptTransform` options.","message":"Do NOT include `.ts` or `.tsx` file extensions in the `options.func.extensions` or `options.trans.extensions` arrays in your `i18next-scanner` configuration. These options are for `i18next-scanner` to process already-JavaScript files. The `typescriptTransform` handles transpilation of TS/TSX independently.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure your project's `typescript` dependency is set to `5.x`. You may need to run `npm install typescript@5` or `yarn add typescript@5` if there's a conflict.","message":"The `i18next-scanner-typescript` package specifies a peer dependency on `typescript` version `5.x`. Using an incompatible version of TypeScript (e.g., 4.x or 6.x) may lead to transpilation errors or unexpected behavior.","severity":"breaking","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Use CommonJS `require` syntax: `const typescriptTransform = require('i18next-scanner-typescript');`","cause":"Attempting to import `i18next-scanner-typescript` using an ES module `import` syntax in a CommonJS context (e.g., a `.js` config file). The package exports a CommonJS module with a default function.","error":"TypeError: (0 , i18next_scanner_typescript_1.default) is not a function"},{"fix":"Verify that `typescriptTransform` is correctly added to the `transform` array in your `i18next-scanner` configuration, and crucially, ensure that `.ts` and `.tsx` are NOT listed in the `options.func.extensions` or `options.trans.extensions`.","cause":"i18next-scanner is attempting to parse a TypeScript file directly because the `typescriptTransform` is either not configured correctly or the `.ts`/`.tsx` extensions are mistakenly included in the main `options.func.extensions` or `options.trans.extensions`.","error":"SyntaxError: 'import' and 'export' may only appear with 'sourceType: module'"}],"ecosystem":"npm"}