nrwl / nx

Smart Monorepos · Fast CI
https://nx.dev
MIT License
23.63k stars 2.36k forks source link

🐞 bug: prettier 3 error `Invalid host defined options` #18721

Closed Yberion closed 1 year ago

Yberion commented 1 year ago

Current Behavior

When trying to format the code with prettier 3, I'm getting an error (check log below).

I'm not sure if it's related to nx or another package (prettier itselft probably), I found this issue https://github.com/prettier/prettier/issues/15098 & https://github.com/prettier/prettier-vscode/issues/3114 and I'm not able to reproduce on nx-examples or another Angular project (using nx as well).


Expected Behavior

Formatting without errors.


GitHub Repo

https://github.com/Yberion/image-utils/tree/feature/prettier3


Steps to Reproduce

  1. pnpm install --no-frozen-lockfile
  2. pnpm run format

Nx Report

>  NX  Falling back to ts-node for local typescript execution. This may be a little slower.
  - To fix this, ensure @swc-node/register and @swc/core have been installed

 >  NX   Report complete - copy this into the issue template

   Node   : 20.5.0
   OS     : win32-x64
   pnpm   : 8.6.12

   nx                 : 16.8.0-beta.0
   @nx/js             : 16.8.0-beta.0
   @nx/linter         : 16.8.0-beta.0
   @nx/workspace      : 16.8.0-beta.0
   @nx/devkit         : 16.8.0-beta.0
   @nx/esbuild        : 16.8.0-beta.0
   @nx/eslint-plugin  : 16.8.0-beta.0
   @nrwl/tao          : 16.8.0-beta.0
   @nx/vite           : 16.8.0-beta.0
   typescript         : 5.1.6

Failure Logs

E:\Git\myberion\image-utils\node_modules\.pnpm\prettier@3.0.2\node_modules\prettier\index.cjs:600
var prettierPromise = import("./index.mjs");
                      ^

TypeError: Invalid host defined options
    at Object.<anonymous> (E:\Git\myberion\image-utils\node_modules\.pnpm\prettier@3.0.2\node_modules\prettier\index.cjs:600:23)
    at Module._compile (E:\Git\myberion\image-utils\node_modules\.pnpm\v8-compile-cache@2.3.0\node_modules\v8-compile-cache\v8-compile-cache.js:192:30)
    at Module._extensions..js (node:internal/modules/cjs/loader:1287:10)
    at Module.load (node:internal/modules/cjs/loader:1091:32)
    at Module._load (node:internal/modules/cjs/loader:938:12)
    at Module.require (node:internal/modules/cjs/loader:1115:19)
    at Mod.require (E:\Git\myberion\image-utils\node_modules\.pnpm\nx@16.8.0-beta.0\node_modules\nx\bin\init-local.js:203:36)
    at require (E:\Git\myberion\image-utils\node_modules\.pnpm\v8-compile-cache@2.3.0\node_modules\v8-compile-cache\v8-compile-cache.js:159:20)
    at Object.<anonymous> (E:\Git\myberion\image-utils\node_modules\.pnpm\nx@16.8.0-beta.0\node_modules\nx\src\command-line\format\format.js:10:18)
    at Module._compile (E:\Git\myberion\image-utils\node_modules\.pnpm\v8-compile-cache@2.3.0\node_modules\v8-compile-cache\v8-compile-cache.js:192:30)

Node.js v20.5.0
 ELIFECYCLE  Command failed with exit code 1.

Operating System


Additional Information

No response

FaresKi commented 1 year ago

I believe nx is currently not able to work with prettier 3, and thus why it breaks

Yberion commented 1 year ago

Hello, it should properly work as of 16.8.0-beta.0.

(edit: I was replying to @FaresKi, I'm still facing the problem on latest version of nx)

Suyashtnt commented 1 year ago

Hello, it should properly work as of 16.8.0-beta.0.

Upgraded to 16.8.0-beta.2. Still have it image

sauldeleon commented 1 year ago

Fails to me as well, latest nrwl and nx and prettier!

cereum commented 1 year ago

likewise

nx/*: 16.8.0-beta.3,
@swc-node/register: ^1.6.7,
@swc/core: ^1.3.80,

TypeError: Invalid host defined options
    at Object.<anonymous> (/Users/cereum/cfx/cfx-b2b-services/node_modules/.pnpm/prettier@3.0.2/node_modules/prettier/index.cjs:600:23)
    at Module._compile (/Users/cereum/cfx/cfx-b2b-services/node_modules/.pnpm/v8-compile-cache@2.3.0/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
    at Module._extensions..js (node:internal/modules/cjs/loader:1287:10)
    at Module.load (node:internal/modules/cjs/loader:1091:32)
    at Module._load (node:internal/modules/cjs/loader:938:12)
    at Module.require (node:internal/modules/cjs/loader:1115:19)
    at Mod.require (/Users/cereum/cfx/cfx-b2b-services/node_modules/.pnpm/nx@16.8.0-beta.3_@swc-node+register@1.6.7_@swc+core@1.3.80/node_modules/nx/bin/init-local.js:203:36)
    at require (/Users/cereum/cfx/cfx-b2b-services/node_modules/.pnpm/v8-compile-cache@2.3.0/node_modules/v8-compile-cache/v8-compile-cache.js:159:20)
    at Object.<anonymous> (/Users/cereum/cfx/cfx-b2b-services/node_modules/.pnpm/nx@16.8.0-beta.3_@swc-node+register@1.6.7_@swc+core@1.3.80/node_modules/nx/src/command-line/format/format.js:11:18)
    at Module._compile (/Users/cereum/cfx/cfx-b2b-services/node_modules/.pnpm/v8-compile-cache@2.3.0/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)

Node.js v20.5.1
guysenpai commented 1 year ago

you can set DISABLE_V8_COMPILE_CACHE environment variable before execute command

DISABLE_V8_COMPILE_CACHE=1 nx format:write
igilham commented 1 year ago

This is not fixed in Nx 16.8.1

yarn nx report

 >  NX   Report complete - copy this into the issue template

   Node   : 18.12.1
   OS     : darwin-arm64
   yarn   : 3.5.1

   nx             : 16.8.1
   @nx/workspace  : 16.8.1
   @nx/devkit     : 16.8.1
   @nrwl/tao      : 16.8.1
   nx-cloud       : 16.4.0
   typescript     : 4.9.5

Error

yarn nx format:check
/Users/ian/code/newsletter/node_modules/prettier/index.cjs:600
var prettierPromise = import("./index.mjs");
                      ^

TypeError: Invalid host defined options
    at Object.<anonymous> (/Users/ian/code/newsletter/node_modules/prettier/index.cjs:600:23)
    at Module._compile (/Users/ian/code/newsletter/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
    at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
    at Module.load (node:internal/modules/cjs/loader:1037:32)
    at Module._load (node:internal/modules/cjs/loader:878:12)
    at Module.require (node:internal/modules/cjs/loader:1061:19)
    at Mod.require (/Users/ian/code/newsletter/node_modules/nx/bin/init-local.js:203:36)
    at require (/Users/ian/code/newsletter/node_modules/v8-compile-cache/v8-compile-cache.js:159:20)
    at Object.<anonymous> (/Users/ian/code/newsletter/node_modules/nx/src/command-line/format/format.js:10:18)
    at Module._compile (/Users/ian/code/newsletter/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)

Node.js v18.12.1

Prettier and related dependencies:

"prettier": "^3.0.3",
"eslint-plugin-prettier": "^5.0.0",
"eslint-config-prettier": "^9.0.0",
"@trivago/prettier-plugin-sort-imports": "^4.2.0",
"eslint": "^8.44.0",
khalilou88 commented 1 year ago

same error

AgentEnder commented 1 year ago

This PR hasn't been released yet, so you'll still get the error. https://github.com/nrwl/nx/pull/19075

khalilou88 commented 1 year ago

thanks fixed in version 16.9

ryanhefner commented 1 year ago

Really? I am still seeing the error in 16.10.0... Any other potential tricks to fix this one?

AgentEnder commented 1 year ago

What command are you running that leads to you hitting the errror?

ryanhefner commented 1 year ago

@AgentEnder Just trying to spin up a new @nx/js lib.

nx g @nx/js:lib types --directory libs/types --bundler rollup
avalero1985 commented 1 year ago

Until it is fixed, I have simply downgraded from prettier to version 2.8.8 and it has worked for me:

"devDependencies": {
  ...
  "prettier": "2.8.8",
  ...
},
github-actions[bot] commented 11 months ago

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.