Riot CLI
Riot CLI is the command-line utility for precompiling Riot.js tags, an open-source UI library. As of its latest stable release, v10.0.0, it wraps the `@riotjs/compiler` to transform Riot.js component files (typically `.riot` files) into standard JavaScript modules. While often installed implicitly with the main `riot` package, it can also be installed and used as a standalone tool. The project follows an active development cycle, releasing major versions to align with new Riot.js framework updates and Node.js environment changes, such as the shift to ESM and stricter Node.js version requirements. Key differentiators include its tight integration with the Riot.js ecosystem, support for various pre-processors and TypeScript, and its ability to not only compile individual tags but also bundle entire Riot.js applications for quick prototypes or development workflows.
Common errors
-
'riot' command not found
cause The `riot-cli` package was not installed globally or is not in your system's PATH.fixInstall globally using `npm install -g riot-cli` or `yarn global add riot-cli`. Ensure your system's PATH includes the npm global bin directory. -
ERR_REQUIRE_ESM or require() of ES Module
cause Attempting to use `require('riot-cli')` programmatically in a CommonJS context, but `riot-cli` has transitioned to ESM since v9.0.0.fixIf programmatic interaction is necessary, switch your project to use ES modules (`import ... from 'riot-cli'`) or consider using `child_process.exec` to run the CLI command directly. -
Error: Node.js version X is not supported by riot-cli. Please upgrade to Node.js vY or higher.
cause Your Node.js environment is older than the minimum version required by the installed riot-cli version.fixUpgrade your Node.js version using a tool like `nvm` (Node Version Manager) to meet the requirements of your riot-cli version (e.g., Node.js >=22 for riot-cli v10+). -
TypeScript compilation error: 'Cannot find name X' or 'Property Y does not exist on type Z'
cause Misconfiguration of TypeScript in your Riot.js project, or using an older riot-cli version without adequate TypeScript support.fixEnsure your `tsconfig.json` is correctly set up for Riot.js components, upgrade `riot-cli` to a version that supports TypeScript (v5.2.0+), and export `RiotComponent` interfaces for proper type checking as per Riot.js documentation.
Warnings
- breaking Node.js version support has been frequently updated. Version 10.0.0 drops support for Node.js versions older than 22.0.0. Earlier, v9.0.0 dropped support for Node.js versions older than 18.0.0.
- breaking Starting with v9.0.0, riot-cli adopted ESM (ECMAScript Module) syntax internally. This change primarily affects consumers attempting programmatic integration who were using CommonJS `require()` statements.
- breaking Major versions of riot-cli (e.g., v6.0.0, v10.0.0) are typically tied to specific major versions of the Riot.js framework and its compiler. Upgrading riot-cli may require corresponding updates to your Riot.js framework dependencies.
- gotcha From v6.1.0 onwards, riot-cli improves bundling by including external npm dependencies directly into its output. This changes how generated bundles might interact with existing module resolution strategies in larger projects.
- gotcha TypeScript support was gradually added around v5.2.0 and v5.3.0. Older versions of riot-cli do not natively support TypeScript syntax within Riot.js tags.
- gotcha Prior to Riot.js v4, the CLI was often bundled with the main `riot` npm package. Since Riot.js v4, `riot-cli` became a separate, explicitly installed package (`npm i -g @riotjs/cli`).
Install
-
npm install riot-cli -
yarn add riot-cli -
pnpm add riot-cli
Imports
- default
const cli = require('riot-cli')import cli from 'riot-cli'
- run
import { run } from 'riot-cli' - version
import { version } from 'riot-cli'
Quickstart
npm install -g riot-cli
# Create a simple Riot.js tag file (e.g., my-component.riot)
// my-component.riot
<my-component>
<h1>Hello, {props.name}!</h1>
<script>
export default {
onMounted() {
console.log('Component mounted with name:', this.props.name)
}
}
</script>
</my-component>
# Compile the tag file to a JavaScript module
riot my-component.riot my-component.js
console.log('my-component.js has been compiled. You can now import and use it in your application.')