{"id":14717,"library":"mrm-task-typescript","title":"Mrm TypeScript Task","description":"mrm-task-typescript is an Mrm task designed to automate the initial setup and configuration of TypeScript within a JavaScript project. It currently stands at version 4.1.22. As part of the Mrm monorepo, its releases are often coordinated with other Mrm tasks, typically seeing version bumps (sometimes 'bump only') to ensure compatibility across the Mrm ecosystem. This task distinguishes itself by providing a declarative and automated way to standardize TypeScript configuration across multiple projects or within an organization, reducing manual setup errors and ensuring best practices are applied consistently. It handles the creation of `tsconfig.json`, integrates a type-checking script into `package.json`, and installs necessary TypeScript-related dependencies, streamlining the developer workflow for adopting TypeScript.","status":"active","version":"4.1.22","language":"javascript","source_language":"en","source_url":"https://github.com/sapegin/mrm","tags":["javascript","mrm","mrm-task","typescript"],"install":[{"cmd":"npm install mrm-task-typescript","lang":"bash","label":"npm"},{"cmd":"yarn add mrm-task-typescript","lang":"bash","label":"yarn"},{"cmd":"pnpm add mrm-task-typescript","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"This package is an Mrm task and requires the Mrm CLI runner to function.","package":"mrm","optional":false}],"imports":[{"note":"This package is an Mrm task, designed for command-line execution, not for direct programmatic import as a module.","wrong":"import { typescript } from 'mrm-task-typescript';","symbol":"mrm-task-typescript","correct":"npx mrm typescript"},{"note":"CommonJS `require` is not applicable as this package is a CLI task and does not expose a module API.","wrong":"const typescript = require('mrm-task-typescript');","symbol":"mrm-task-typescript","correct":"npx mrm typescript"},{"note":"There is no default export; the task's functionality is accessed exclusively through the Mrm CLI.","wrong":"import typescript from 'mrm-task-typescript';","symbol":"mrm-task-typescript","correct":"npx mrm typescript"}],"quickstart":{"code":"import * as path from 'path';\nimport * as fs from 'fs';\nimport { execSync } from 'child_process';\n\nconst projectName = 'my-ts-project';\nconst projectPath = path.join(process.cwd(), projectName);\n\nconsole.log(`Creating project directory: ${projectPath}`);\nfs.mkdirSync(projectPath, { recursive: true });\nprocess.chdir(projectPath);\n\nconsole.log('Initializing npm...');\nexecSync('npm init -y', { stdio: 'inherit' });\n\nconsole.log('Running mrm typescript task...');\nexecSync('npx mrm typescript', { stdio: 'inherit' });\n\nconsole.log('\\nVerifying setup:');\nconsole.log('Content of tsconfig.json:');\nconsole.log(fs.readFileSync('tsconfig.json', 'utf8'));\n\nconsole.log('\\nContent of package.json scripts:');\nconst packageJson = JSON.parse(fs.readFileSync('package.json', 'utf8'));\nconsole.log(packageJson.scripts);\n\n// Create a sample TypeScript file to demonstrate compilation\nfs.mkdirSync('src', { recursive: true });\nfs.writeFileSync('src/index.ts', `\nfunction greet(name: string): string {\n  return \\`Hello, \\${name}!\\`;\n}\nconsole.log(greet(\"TypeScript User\"));\n`);\n\nconsole.log('\\nAttempting to run type check script...');\nexecSync('npm run typecheck', { stdio: 'inherit' });\n\nconsole.log('\\nTypeScript setup complete! To clean up, run:');\nconsole.log(`rm -rf ${projectName}`);","lang":"typescript","description":"Demonstrates how to create a new project, initialize npm, and apply the `mrm typescript` task to configure TypeScript, including `tsconfig.json` and a type-checking script."},"warnings":[{"fix":"Upgrade Node.js to a compatible version (e.g., using `nvm install 18` or `nvm use 18`).","message":"Ensure your Node.js environment meets the minimum requirement (>=10.13) as specified in the package's `engines` field. Using older Node.js versions may lead to unexpected errors.","severity":"gotcha","affected_versions":"<=4.1.22"},{"fix":"Back up critical configuration files before running Mrm. After the task, manually merge or adjust configurations as necessary.","message":"Mrm tasks can overwrite existing configuration files. If you have an existing `tsconfig.json` or related npm scripts, review the changes made by the task to ensure they align with your project's needs.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use `npx mrm typescript` or ensure `mrm` is installed globally (`npm install -g mrm`) and its bin directory is in your system's PATH.","message":"The Mrm task runner (`mrm`) must be accessible in your PATH. While `npx` handles this for global installs, ensure `mrm` itself is installed or resolvable if you're not using `npx`.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Always navigate to your project's root directory before executing `npx mrm typescript`.","message":"Mrm tasks are designed to be run in the root directory of your project where `package.json` resides. Running them from subdirectories can lead to incorrect file placements or configuration.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"After running the task, check `package.json` for installed TypeScript dependencies and resolve any version conflicts manually if needed. You may need to run `npm install` again.","message":"The specific versions of TypeScript and `@types` packages installed by this task are managed by the task's internal logic. These might conflict with pre-existing versions in your `package.json` or require specific TypeScript versions for compilation.","severity":"gotcha","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 `npx mrm typescript` or install Mrm globally with `npm install -g mrm`.","cause":"The Mrm command-line interface tool is not installed globally or accessible via npx.","error":"command not found: mrm"},{"fix":"Ensure you have write permissions in the project directory. On some systems, you might need to run your terminal with elevated privileges (e.g., `sudo npx mrm typescript` on Linux/macOS or 'Run as Administrator' on Windows).","cause":"Permission issues prevent Mrm from creating necessary directories or files in the project path.","error":"Error: EPERM: operation not permitted, mkdir 'src'"},{"fix":"After running `npx mrm typescript`, ensure you run `npm install` (or `yarn install`) to install all project dependencies, including TypeScript.","cause":"The TypeScript package, which is a dependency managed by the task, was not successfully installed in your project's `node_modules`.","error":"Cannot find module 'typescript'"},{"fix":"Verify your `package.json` for the presence of a `scripts.typecheck` entry. If missing, re-run `npx mrm typescript` or manually add `\"typecheck\": \"tsc --noEmit\"` to your `scripts`.","cause":"The `typecheck` npm script was not correctly added to your `package.json` by the Mrm task.","error":"Missing script: 'typecheck'"}],"ecosystem":"npm"}