Zalo Mini App CLI
The `zmp-cli` is a command-line interface utility designed to streamline the development, testing, and deployment of Zalo Mini Apps. It provides essential commands for developer login, project creation, building, previewing, and deployment, offering an alternative to the Zalo Mini App Extension. Currently at version 4.0.3, the package was last published a month ago as of March 2026, indicating active maintenance. It focuses on integrating into various IDEs and CI/CD pipelines for automation. Key differentiators include its ability to convert existing web applications into Zalo Mini Apps and its support for both QR code and access token-based authentication. Its primary mode of interaction is through shell commands, though it also exposes a programmatic interface for advanced automation in JavaScript/TypeScript environments.
Common errors
-
zmp: command not found
cause The Zalo Mini App CLI (zmp-cli) is not installed globally or is not in your system's PATH.fixRun `npm install -g zmp-cli` to install it globally. If it's already installed, ensure your `npm` global binaries directory is in your system's PATH environment variable, or try `npx zmp <command>`. -
Login failed: Invalid Access Token
cause The provided access token is expired, revoked, or incorrect, preventing authentication with the Zalo developer platform.fixObtain a fresh access token from the Zalo for Developers portal (Công cụ > API Explorer > Lấy Access Token) and ensure it's for the correct Zalo App. Re-run `zmp login` or pass the new token explicitly if using programmatic authentication. -
Error: Zalo Mini App ID is required
cause During project initialization or deployment, a valid Zalo Mini App ID was not provided or configured.fixEnsure you have registered your Mini App on mini.zalo.me/developers and have obtained an App ID. When prompted by `zmp init` or `zmp deploy`, provide the correct Zalo Mini App ID. -
Project requires Vite 2.x for Device mode. Webpack projects are not compatible.
cause When attempting to run `zmp start -D` (Device mode), the CLI detected that the project is using Webpack instead of Vite 2.x or newer.fixTo use Device mode, your Zalo Mini App project must be configured with Vite 2.x. Consider migrating your project build system to Vite or use the standard `zmp start` command for browser preview mode instead.
Warnings
- breaking Major version updates (e.g., from v3 to v4) for `zmp-cli` may introduce breaking changes in command-line arguments, options, or output formats. Always consult the official release notes before upgrading in CI/CD environments or scripts.
- gotcha Authentication methods for `zmp login` include QR code scanning via the Zalo mobile app or providing an access token. QR codes have a limited lifespan, and access tokens can expire. Ensure tokens are fresh or be prepared to re-authenticate frequently.
- gotcha While `npm install -g zmp-cli` provides a global `zmp` command, you might encounter issues with different Node.js versions or permissions. Alternatively, using `npx zmp` will execute the latest version without global installation, or execute a locally installed version.
- gotcha When initializing a new project with `zmp init`, the CLI offers two modes: 'Create a new ZMP project' which generates a new directory, or 'Use ZMP to deploy only' which modifies the current working directory. Misunderstanding this choice can lead to unexpected file creation or overwrites.
Install
-
npm install zmp-cli -
yarn add zmp-cli -
pnpm add zmp-cli
Imports
- login
import login from 'zmp-cli'; // 'login' is a named export, not default.
import { login } from 'zmp-cli'; - init
const { init } = require('zmp-cli'); // Primarily ESM; CJS might have issues or require transpilation.import { init } from 'zmp-cli'; - deploy
import * as zmp from 'zmp-cli'; zmp.deploy(); // While technically correct, direct named import is preferred.
import { deploy } from 'zmp-cli';
Quickstart
import { login, init } from 'zmp-cli';
import { exec } from 'child_process';
// --- CLI Usage ---
console.log('--- CLI Usage ---');
exec('npm install -g zmp-cli', (err, stdout, stderr) => {
if (err) {
console.error(`CLI install error: ${stderr}`);
return;
}
console.log('Zalo Mini App CLI installed globally.');
exec('zmp --help', (err, stdout, stderr) => {
if (err) {
console.error(`zmp --help error: ${stderr}`);
return;
}
console.log('zmp --help output:\n', stdout.substring(0, 200) + '...');
console.log('\nRun `zmp login` to authenticate or `zmp init` to create a project.');
console.log('For example: `zmp login` will prompt for QR code or access token.');
console.log('Or: `zmp init` will guide through project creation.');
// --- Programmatic Usage (Conceptual) ---
console.log('\n--- Programmatic Usage (Conceptual) ---');
async function automateZmp() {
try {
console.log('Attempting programmatic login (this will likely open a browser/terminal prompt).');
// In a real scenario, you might pass an access token directly if the API supports it.
// For now, this acts as an example of calling the exported function.
await login();
console.log('Login initiated programmatically. Please complete in browser/terminal.');
console.log('Initiating a new Zalo Mini App project programmatically (e.g., in a temp directory).');
// For actual programmatic init, you'd provide options like project name, template, etc.
// await init({ name: 'my-automated-app', template: 'blank', appId: process.env.ZMP_APP_ID ?? '' });
console.log('`init()` function would be called here with specific options.');
} catch (error) {
console.error('Programmatic ZMP operation failed:', error);
}
}
// automateZmp(); // Uncomment to run the programmatic example
});
});