nx
nx copied to clipboard
Prettier is not working anymore
Current Behavior
If I want to format the code with prettier I get an error in the output and the code isn't formatted.
Expected Behavior
Format the code with prettier without an error
GitHub Repo
No response
Steps to Reproduce
- Create a Nx Workspace with
npx create-nx-workspace@latestwith an Angular mono repo - Open
app.component.tsand make any changes - Format the code using
prettier
Nx Report
> NX Report complete - copy this into the issue template
Node : 18.12.1
OS : win32 x64
npm : 8.19.2
nx : 15.9.2
@nrwl/js : 15.9.2
@nrwl/jest : 15.9.2
@nrwl/linter : 15.9.2
@nrwl/workspace : 15.9.2
@nrwl/angular : 15.9.2
@nrwl/cli : 15.9.2
@nrwl/cypress : 15.9.2
@nrwl/devkit : 15.9.2
@nrwl/eslint-plugin-nx : 15.9.2
@nrwl/tao : 15.9.2
@nrwl/web : 15.9.2
@nrwl/webpack : 15.9.2
typescript : 4.9.5
Failure Logs
["INFO" - 2:55:34 PM] Formatting file:///c%3A/[REDACTED]/projects/test/apps/client/src/app/app.component.ts
["INFO" - 2:55:34 PM] Using config file at 'c:\[REDACTED]\projects\test\.eslintrc.json'
["ERROR" - 2:55:34 PM] Error resolve node module '@nrwl/nx'
["ERROR" - 2:55:34 PM] Cannot find module '@nrwl/nx'
Require stack:
- c:\[REDACTED]\.vscode\extensions\esbenp.prettier-vscode-9.10.4\dist\extension.js
- c:\[REDACTED]\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\loader.js
- c:\[REDACTED]\AppData\Local\Programs\Microsoft VS Code\resources\app\out\bootstrap-amd.js
- c:\[REDACTED]\AppData\Local\Programs\Microsoft VS Code\resources\app\out\bootstrap-fork.js
-
Error: Cannot find module '@nrwl/nx'
Require stack:
- c:\[REDACTED]\.vscode\extensions\esbenp.prettier-vscode-9.10.4\dist\extension.js
- c:\[REDACTED]\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\loader.js
- c:\[REDACTED]\AppData\Local\Programs\Microsoft VS Code\resources\app\out\bootstrap-amd.js
- c:\[REDACTED]\AppData\Local\Programs\Microsoft VS Code\resources\app\out\bootstrap-fork.js
-
at Module._resolveFilename (node:internal/modules/cjs/loader:987:15)
at Function.i._resolveFilename (node:electron/js2c/utility_init:17:840)
at Function.g.resolve (c:\[REDACTED]\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\loader.js:4:709)
at t.ModuleResolver.resolveNodeModule (c:\[REDACTED]\.vscode\extensions\esbenp.prettier-vscode-9.10.4\dist\extension.js:1:6553)
at c:\[REDACTED]\.vscode\extensions\esbenp.prettier-vscode-9.10.4\dist\extension.js:1:6787
at Array.map (<anonymous>)
at t.ModuleResolver.resolveConfigPlugins (c:\[REDACTED]\.vscode\extensions\esbenp.prettier-vscode-9.10.4\dist\extension.js:1:6717)
at t.ModuleResolver.getResolvedConfig (c:\[REDACTED]\.vscode\extensions\esbenp.prettier-vscode-9.10.4\dist\extension.js:1:5974)
at t.default.format (c:\[REDACTED]\.vscode\extensions\esbenp.prettier-vscode-9.10.4\dist\extension.js:1:13308)
at t.PrettierEditProvider.provideEdits (c:\[REDACTED]\.vscode\extensions\esbenp.prettier-vscode-9.10.4\dist\extension.js:1:11417)
at B.provideDocumentFormattingEdits (c:\[REDACTED]\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:100:46615)
["INFO" - 2:55:34 PM] Using ignore file (if present) at c:\[REDACTED]\projects\test\.prettierignore
["INFO" - 2:55:34 PM] File Info:
{
"ignored": false,
"inferredParser": "typescript"
}
["INFO" - 2:55:34 PM] Detected local configuration (i.e. .prettierrc or .editorconfig), VS Code configuration will not be used
["INFO" - 2:55:34 PM] Prettier Options:
{
"filepath": "c:\\[REDACTED]\\projects\\test\\apps\\client\\src\\app\\app.component.ts",
"parser": "typescript",
"useTabs": false,
"tabWidth": 2,
"root": true,
"ignorePatterns": [
"**/*"
],
"plugins": [
"@nrwl/nx"
]
}
["ERROR" - 2:55:34 PM] Error formatting document.
["ERROR" - 2:55:34 PM] Cannot find module '@nrwl/nx'
Require stack:
- c:\[REDACTED]\projects\test\node_modules\prettier\index.js
- c:\[REDACTED]\.vscode\extensions\esbenp.prettier-vscode-9.10.4\dist\extension.js
- c:\[REDACTED]\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\loader.js
- c:\[REDACTED]\AppData\Local\Programs\Microsoft VS Code\resources\app\out\bootstrap-amd.js
- c:\[REDACTED]\AppData\Local\Programs\Microsoft VS Code\resources\app\out\bootstrap-fork.js
-
Error: Cannot find module '@nrwl/nx'
Require stack:
- c:\[REDACTED]\projects\test\node_modules\prettier\index.js
- c:\[REDACTED]\.vscode\extensions\esbenp.prettier-vscode-9.10.4\dist\extension.js
- c:\[REDACTED]\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\loader.js
- c:\[REDACTED]\AppData\Local\Programs\Microsoft VS Code\resources\app\out\bootstrap-amd.js
- c:\[REDACTED]\AppData\Local\Programs\Microsoft VS Code\resources\app\out\bootstrap-fork.js
-
at Module._resolveFilename (node:internal/modules/cjs/loader:987:15)
at Function.i._resolveFilename (node:electron/js2c/utility_init:17:840)
at g.resolve (c:\[REDACTED]\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\loader.js:4:709)
at c:\[REDACTED]\projects\test\node_modules\prettier\index.js:38119:25
at Array.map (<anonymous>)
at Object.load (c:\[REDACTED]\projects\test\node_modules\prettier\index.js:38114:65)
at Object.load [as loadPlugins] (c:\[REDACTED]\projects\test\node_modules\prettier\index.js:16147:23)
at c:\[REDACTED]\projects\test\node_modules\prettier\index.js:38181:24
at Object.format (c:\[REDACTED]\projects\test\node_modules\prettier\index.js:38197:12)
at t.default.format (c:\[REDACTED]\.vscode\extensions\esbenp.prettier-vscode-9.10.4\dist\extension.js:1:14731)
at t.PrettierEditProvider.provideEdits (c:\[REDACTED]\.vscode\extensions\esbenp.prettier-vscode-9.10.4\dist\extension.js:1:11417)
at B.provideDocumentFormattingEdits (c:\[REDACTED]\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:100:46615)
["INFO" - 2:55:34 PM] Formatting completed in 13ms.
Additional Information
package.json
{
"name": "test",
"version": "0.0.0",
"license": "MIT",
"scripts": {},
"private": true,
"dependencies": {
"@angular/animations": "~15.2.0",
"@angular/common": "~15.2.0",
"@angular/compiler": "~15.2.0",
"@angular/core": "~15.2.0",
"@angular/forms": "~15.2.0",
"@angular/platform-browser": "~15.2.0",
"@angular/platform-browser-dynamic": "~15.2.0",
"@angular/router": "~15.2.0",
"@nrwl/angular": "15.9.2",
"rxjs": "~7.8.0",
"tslib": "^2.3.0",
"zone.js": "~0.12.0"
},
"devDependencies": {
"@angular-devkit/build-angular": "~15.2.0",
"@angular-devkit/core": "~15.2.0",
"@angular-devkit/schematics": "~15.2.0",
"@angular-eslint/eslint-plugin": "~15.0.0",
"@angular-eslint/eslint-plugin-template": "~15.0.0",
"@angular-eslint/template-parser": "~15.0.0",
"@angular/cli": "~15.2.0",
"@angular/compiler-cli": "~15.2.0",
"@angular/language-service": "~15.2.0",
"@nrwl/cypress": "15.9.2",
"@nrwl/eslint-plugin-nx": "15.9.2",
"@nrwl/jest": "15.9.2",
"@nrwl/js": "15.9.2",
"@nrwl/linter": "15.9.2",
"@nrwl/web": "15.9.2",
"@nrwl/workspace": "15.9.2",
"@schematics/angular": "~15.2.0",
"@types/jest": "^29.4.0",
"@types/node": "16.11.7",
"@typescript-eslint/eslint-plugin": "^5.36.1",
"@typescript-eslint/parser": "^5.36.1",
"cypress": "^12.2.0",
"eslint": "~8.15.0",
"eslint-config-prettier": "8.1.0",
"eslint-plugin-cypress": "^2.10.3",
"jest": "^29.4.1",
"jest-environment-jsdom": "^29.4.1",
"jest-preset-angular": "~13.0.0",
"nx": "15.9.2",
"prettier": "^2.6.2",
"ts-jest": "^29.0.5",
"ts-node": "10.9.1",
"typescript": "~4.9.5"
}
}
Hi there @arndwestermann ! Thanks for filing this bug. Does your issue go away if you install @nrwl/nx?
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
I had the same issue updating to prettier v3.0.0, downgrading to 2.8.8 fixed for now.
I have the same issue as @sebpalluel. It would be great if someone from the Nx team could have a look.
I have the same issue as @sebpalluel. It would be great if someone from the Nx team could have a look.
@AgentEnder maybe
Prettier v3 support is unrelated to the original issue here. Nx should support prettier v3 fully as of latest. If you hit an issue with prettier v3 please open a new issue.
I'm going to close this one out since its been a bit derailed from the original discussion and we've not heard back from @arndwestermann .
I had same issue this week, I downgraded to prettier@^2
I had same issue this week, I downgraded to
prettier@^2
Well i can confirm that i don't have any issue on my end with "prettier": "^3.0.3" and nx version 17.0.2 so the solution might be to upgrade your nx monorepo to the latest version.
This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.