Udemy Prettier Config

raw JSON →
1.0.8 verified Sat Apr 25 auth: no javascript

Udemy's shared Prettier configuration for ES2015 JavaScript code. Version 1.0.8 is the latest stable release. The package is maintained by Udemy for internal projects but is publicly available. It relies on Prettier as a peer dependency and uses CommonJS module.exports. The config can be extended and overridden in a .prettierrc.js file.

error SyntaxError: Cannot use import statement outside a module
cause Using ESM import with a CommonJS package in a .prettierrc.js file that is treated as CJS by default.
fix
Change to: module.exports = { ...require('prettier-config-udemy-website'), ... };
error Error: Cannot find module 'prettier-config-udemy-website'
cause The package is not installed or not in node_modules.
fix
Run: yarn add prettier-config-udemy-website --dev
error TypeError: Cannot read properties of undefined (reading 'printWidth')
cause The config object is not spread correctly; perhaps require returned an object with no own properties.
fix
Ensure spread syntax is used correctly: module.exports = { ...require('prettier-config-udemy-website'), printWidth: 140 };
gotcha Only compatible with Prettier v1.x? Version 1.0.8 may not support Prettier v2+ options like 'embeddedLanguageFormatting'.
fix Check Prettier version compatibility. Consider using official @udemy/prettier-config if available.
gotcha CommonJS only. Direct import using ESM (import) will throw SyntaxError.
fix Use require() or ensure your project uses CommonJS (e.g., .prettierrc.js).
gotcha No TypeScript definitions. Using with TypeScript may require a custom .d.ts file.
fix Create a declaration: declare module 'prettier-config-udemy-website' { const config: Record<string, any>; export = config; }
gotcha Package is unmaintained (last release 6+ years ago). May not include modern Prettier options.
fix Consider using Prettier's built-in 'prettier.config.js' or forking the config.
npm install prettier-config-udemy-website
yarn add prettier-config-udemy-website
pnpm add prettier-config-udemy-website

Creates a .prettierrc.js that extends Udemy's Prettier config with custom overrides.

// .prettierrc.js
module.exports = {
  ...require('prettier-config-udemy-website'),
  printWidth: 140,
  tabWidth: 4
};