razzle-plugin-typescript integrates TypeScript support into Razzle applications, allowing developers to use TypeScript for both client-side and server-side code. It provides granular configuration options for underlying tools like `ts-loader` and `fork-ts-checker-webpack-plugin`, enabling custom setups for compilation and type checking. The package is currently at version 4.2.18, receiving updates in sync with the core Razzle framework. A key consideration is that Razzle now includes built-in TypeScript support via Babel. As such, this plugin is primarily recommended for projects requiring advanced or specific TypeScript configurations, such as applying certain Babel transforms to `.ts` files, rather than for basic TypeScript integration, where the native Razzle support is generally sufficient and simpler.
npm install razzle-plugin-typescriptVerified import paths — ran on the pinned version, not inferred.
This configuration enables the TypeScript plugin in Razzle with custom `ts-loader` and `fork-ts-checker-webpack-plugin` options, and adds TypeScript extensions to Webpack's resolution paths.
Consider removing `razzle-plugin-typescript` and configuring TypeScript directly via Razzle's core features or Babel settings, as demonstrated in Razzle's `with-typescript` example.
Ensure your `razzle.config.js` matches your project's module system. If using ESM `import/export` in `razzle.config.js`, add `"type": "module"` to your `package.json`. Otherwise, stick to CommonJS `require/module.exports` syntax.
Install required packages: `yarn add -D typescript ts-loader fork-ts-checker-webpack-plugin` or `npm install --save-dev typescript ts-loader fork-ts-checker-webpack-plugin`. Also ensure a `tsconfig.json` file is present in your project root.
In your `package.json`, add `"type": "module"` at the top level to enable ESM. Alternatively, rewrite your `razzle.config.js` to use CommonJS `require()` and `module.exports` syntax.
Ensure `typescript`, `ts-loader`, and `fork-ts-checker-webpack-plugin` are installed as dev dependencies (`yarn add -D typescript ts-loader fork-ts-checker-webpack-plugin`). Verify that a valid `tsconfig.json` exists in your project root and is correctly configured for your project structure.
Address the specific TypeScript error message by correcting your code, adjusting your `tsconfig.json` compiler options (e.g., `skipLibCheck`, `noImplicitAny`, `jsx`), or installing `@types/` packages for untyped dependencies. Check `forkTsChecker` options for specific linting rules if applicable.