{"id":20391,"library":"prettier-plugin-multiline-arrays","title":"prettier-plugin-multiline-arrays","description":"Prettier plugin that forces array elements to wrap onto new lines, with control over how many elements appear per line via `multilineArraysWrapThreshold` (default -1, no auto wrap) and `multilineArraysLinePattern` (default '1', one element per line). TypeScript, JavaScript, and JSON supported. Current stable version 4.1.7, requires Prettier >=3.0.0 <4.0.0 and Node >=20. Ships TypeScript types. Differentiated by comment overrides per array and set/reset patterns. Maintained by electrovir.","status":"active","version":"4.1.7","language":"javascript","source_language":"en","source_url":"https://github.com/electrovir/prettier-plugin-multiline-arrays","tags":["javascript","array","format","multiline","plugin","prettier","printer","typescript"],"install":[{"cmd":"npm install prettier-plugin-multiline-arrays","lang":"bash","label":"npm"},{"cmd":"yarn add prettier-plugin-multiline-arrays","lang":"bash","label":"yarn"},{"cmd":"pnpm add prettier-plugin-multiline-arrays","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"This is a Prettier plugin and requires Prettier >=3.0.0 <4.0.0 as a peer dependency.","package":"prettier","optional":false}],"imports":[{"note":"ESM-only since v4. The package ships ESM. CJS require will fail. Use dynamic import or configure your project for ESM.","wrong":"const prettierPluginMultilineArrays = require('prettier-plugin-multiline-arrays')","symbol":"default","correct":"import prettierPluginMultilineArrays from 'prettier-plugin-multiline-arrays'"},{"note":"Register the plugin by name in the plugins array. Do not use a file path. The plugin name string is sufficient.","wrong":"plugins: ['./node_modules/prettier-plugin-multiline-arrays']","symbol":"options (Prettier config usage)","correct":"// In prettier.config.mjs:\nexport default {\n  plugins: ['prettier-plugin-multiline-arrays'],\n  multilineArraysWrapThreshold: 3,\n  multilineArraysLinePattern: '2 1'\n}"}],"quickstart":{"code":"// Install: npm install --save-dev prettier prettier-plugin-multiline-arrays\n\n// prettier.config.mjs\nexport default {\n  plugins: ['prettier-plugin-multiline-arrays'],\n  multilineArraysWrapThreshold: 2, // wrap arrays with >2 elements\n  multilineArraysLinePattern: '2 1', // first line 2 items, second line 1, repeat\n};\n\n// Example input (before formatting):\nconst arr = ['a', 'b', 'c', 'd'];\n\n// After prettier (with above config):\nconst arr = [\n  'a', 'b',\n  'c', 'd',\n];","lang":"typescript","description":"Install and configure the plugin, then run Prettier to see multiline array formatting."},"warnings":[{"fix":"Upgrade Prettier to ^3.0.0 and ensure Node >=16 (v4.1.7 requires Node >=20).","message":"v4.0.0 dropped support for Prettier 2.x and earlier. Requires Prettier >=3.0.0.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Use ESM imports or dynamic import(). If you cannot switch to ESM, stay on v3.x.","message":"v4.0.0 switched to ESM-only. CommonJS require() will fail.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Place 'prettier-plugin-multiline-arrays' before other plugins that modify formatting of arrays. Check the plugin's own Prettier config for reference.","message":"Plugin order among multiple plugins can affect behavior. The documentation recommends rearranging if other plugins interfere.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"If you need line-length enforcement, set a pattern that fits within your desired column width, or rely on Prettier's default wrapping by not setting this option.","message":"The `multilineArraysLinePattern` option overrides Prettier's default line-length-based wrapping for arrays. Arrays may exceed the column limit if the pattern forces more items per line than can fit.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use `// prettier-multiline-arrays-set-threshold: 4` to apply to all subsequent arrays, then `// prettier-multiline-arrays-reset` to revert.","message":"Comment overrides (e.g., `// prettier-multiline-arrays-next-threshold: 4`) apply to the next line only. For persistent overrides, use `set-` variants.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Switch to ESM (use import, add 'type': 'module' in package.json) or use dynamic import() in CommonJS: const plugin = await import('prettier-plugin-multiline-arrays');","cause":"The package is ESM-only from v4, but you are using require() in a CommonJS context.","error":"Error [ERR_REQUIRE_ESM]: require() of ES Module /path/to/node_modules/prettier-plugin-multiline-arrays/dist/index.js from /path/to/not-supported.js not supported."},{"fix":"Ensure the plugin is installed: `npm install --save-dev prettier-plugin-multiline-arrays`. If using a monorepo, ensure it's in the root or hoisted.","cause":"Plugin not installed or not in the correct node_modules path.","error":"[prettier] Cannot find module 'prettier-plugin-multiline-arrays'"},{"fix":"Upgrade Prettier to ^3.0.0 and node to >=20 as required by the plugin's engine.","cause":"Incompatible Prettier version - this plugin requires Prettier 3.x.","error":"TypeError: Cannot read properties of undefined (reading 'length')","affected_versions":">=4.0.0"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}