nx
nx copied to clipboard
prettier@3+ integration
Some breaking changes were introduced with the new version of prettier.
It looks like at the very least this like will need updating:
- (
const PRETTIER_PATH = require.resolve('prettier/bin-prettier');) https://github.com/nrwl/nx/blob/64765eb313d33c93bd4db35d86b21ecb43fa5757/packages/nx/src/command-line/format/format.ts#L26
due to this change:
- (
bin-prettier.js->bin/prettier.cjs) https://github.com/prettier/prettier/blob/e2f4ce38f7c1dac1d1ec5371670a93e3844f6b39/website/blog/2023-07-05-3.0.0.md?plain=1#L334
I have a different issue while updating prettier to the latest version `v3.0.0`:
> NX Running global Nx CLI with PNPM may have issues.
Prefer to use "pnpm" (https://pnpm.io/cli/exec) to execute commands in this workspace.
TIP create a shortcut such as: alias pnx="pnpm nx --"
nx format:check
Check for un-formatted files
Run command using --base=[SHA1] (affected by the committed, uncommitted and untracked changes):
--base Base of the current branch (usually main) [string]
or using --base=[SHA1] --head=[SHA2] (affected by the committed changes):
--base Base of the current branch (usually main) [string]
--head Latest commit of the current branch (usually HEAD) [string]
or using:
--files Change the way Nx is calculating the affected command by providing directly
changed files, list of files delimited by commas or spaces [string]
--uncommitted Uncommitted changes [boolean]
--untracked Untracked changes [boolean]
Options:
--help Show help [boolean]
--version Show version number [boolean]
--exclude Exclude certain projects from being processed [string]
--libs-and-apps Format only libraries and applications files. [boolean]
--projects Projects to format (comma/space delimited) [string]
--all Format all projects [boolean]
Find more information and examples at https://nx.dev/nx/format-check
Error: Cannot find module '/Users/sebpalluel/Documents/dev/offline/marketplace/node_modules/prettier/bin-prettier'
at createEsmNotFoundErr (node:internal/modules/cjs/loader:1104:15)
at finalizeEsmResolution (node:internal/modules/cjs/loader:1097:15)
at resolveExports (node:internal/modules/cjs/loader:569:14)
at Module._findPath (node:internal/modules/cjs/loader:643:31)
at Module._resolveFilename (node:internal/modules/cjs/loader:1068:27)
at Function.resolve (/Users/sebpalluel/Documents/dev/offline/marketplace/node_modules/.pnpm/[email protected]/node_modules/v8-compile-cache/v8-compile-cache.js:164:23)
at Object.<anonymous> (/Users/sebpalluel/Documents/dev/offline/marketplace/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]/node_modules/nx/src/command-line/format/format.js:18:31)
at Module._compile (/Users/sebpalluel/Documents/dev/offline/marketplace/node_modules/.pnpm/[email protected]/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
at Module._extensions..js (node:internal/modules/cjs/loader:1321:10)
at Module.load (node:internal/modules/cjs/loader:1125:32) {
code: 'MODULE_NOT_FOUND',
path: '/Users/sebpalluel/Documents/dev/offline/marketplace/node_modules/prettier/package.json'
}
I'm using the latest version of nx 16.5.0
Originally posted by @sebpalluel in https://github.com/nrwl/nx/issues/16121#issuecomment-1623239059