Init command for project initialization

The init command initializes a Magnolia CLI project in your current directory. It automatically detects your project type and configures the necessary files and dependencies.

Running the command

In your project directory, run:

npx @magnolia/cli@latest init

The command does the following steps:

  • Detect the project type.

  • Create or validate the package.json with "type": "module".

  • Install the @magnolia/cli as a dependency.

  • Add the "mgnl": "node node_modules/@magnolia/cli" script.

  • Create the mgnl.config.js (or mgnl.config.mjs, for CommonJS projects),

  • For Headless Accelerator projects: Run ha install if available.

For Headless Accelerator projects, ensure that the ha-cli and ha commands are installed. For more details, see the HA Documentation.
If your project has already been initialized, the command detects this and exits without making any changes.

Next steps

After the initialization:

  1. Browse the available plugins to find the ones you need.

  2. Add plugins: npm run mgnl — add-plugin <plugin-name>.

  3. Run CLI commands as needed.

Troubleshooting

Fixing errors

Error type How to fix

Invalid package.json

Fix the syntax errors before running the init again.

mgnl.config.js file errors

Review and fix import or syntax errors in your config file.

Headless Accelerator setup failures

Run ha install manually if needed. For more details, see the HA Documentation

Feedback

DX Core

×

Location

This widget lets you know where you are on the docs site.

You are currently perusing through the Magnolia CLI docs.

Main doc sections

DX Core Headless PaaS Legacy Cloud Incubator modules