Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

formatFiles in generator fails with TypeError (received Promise instead of Buffer like) #18308

Closed
1 of 4 tasks
qortex opened this issue Jul 25, 2023 · 9 comments
Closed
1 of 4 tasks

Comments

@qortex
Copy link
Contributor

qortex commented Jul 25, 2023

Current Behavior

When using formatFiles in a generator, calling formatFiles(tree) as usual, it starts giving this error:

image

Up until last update, it worked flawlessly.

Generators continues, but files are not formatted.

Expected Behavior

Files should be formatted without error.

GitHub Repo

No response

Steps to Reproduce

Nx Report

Node   : 18.17.0
   OS     : darwin-arm64
   yarn   : 1.22.19
   
   nx                 : 16.5.3
   @nx/js             : 16.5.3
   @nx/jest           : 16.5.3
   @nx/linter         : 16.5.3
   @nx/workspace      : 16.5.3
   @nx/angular        : 16.5.3
   @nx/cypress        : 16.5.3
   @nx/devkit         : 16.5.3
   @nx/eslint-plugin  : 16.5.3
   @nx/nest           : 16.5.3
   @nx/node           : 16.5.3
   @nx/plugin         : 16.5.3
   @nx/storybook      : 16.5.3
   @nrwl/tao          : 16.5.3
   @nx/webpack        : 16.5.3
   typescript         : 5.1.6
   ---------------------------------------
   Community plugins:
   @auth0/auth0-angular  : 1.11.1
   @compodoc/compodoc    : 1.1.21
   @ngneat/svg-icon      : 7.0.0
   @ngneat/tailwind      : 7.0.3
   @ngneat/transloco     : 4.3.0
   @ngrx/component       : 16.1.0
   @ngrx/component-store : 16.1.0
   @ngrx/effects         : 16.1.0
   @ngrx/entity          : 16.1.0
   @ngrx/router-store    : 16.1.0
   @ngrx/schematics      : 16.1.0
   @ngrx/store           : 16.1.0
   @ngrx/store-devtools  : 16.1.0
   @storybook/angular    : 7.1.0
   apollo-angular        : 5.0.0
   eslint-plugin-ngrx    : 2.1.4
   ---------------------------------------
   Local workspace plugins:
   	 @qontrol/event-sourcing
   	 @monorepo/qontrol-event-sourcing
   	 @monorepo/workspace-plugin

Failure Logs

TypeError: The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received an instance of Promise
    at new NodeError (node:internal/errors:405:5)
    at Function.from (node:buffer:333:9)
    at FsTree.write (/Users/mic/dev/qontrol/monorepo/node_modules/nx/src/generators/tree.js:63:33)
    at /Users/mic/dev/qontrol/monorepo/node_modules/@nx/devkit/src/generators/format-files.js:40:22
    at Generator.next (<anonymous>)
    at fulfilled (/Users/mic/dev/qontrol/monorepo/node_modules/@nx/devkit/node_modules/tslib/tslib.js:115:62)

Operating System

  • macOS
  • Linux
  • Windows
  • Other (Please specify)

Additional Information

Used to work.

Did not have the time to track the issue in the code for now, just wanted to post and let people +1 if they see the issue too.

@schmkr
Copy link

schmkr commented Aug 2, 2023

Running into this issue too, when migrating from 15.9.4 to 16.6.0.

I suspected this to be a result of our repo using Prettier v3, so I downgraded to 2.8.8 and ran all migrations again (I could revert all of them easily because we use --create-commits when running the migrations).

I can confirm this did solve the issue for us, using Prettier v2.

@danjor
Copy link
Contributor

danjor commented Aug 10, 2023

Hello,

I'm having also this issue with Nx 16.6.0 and prettier v3 on Windows.

@mlc-mlapis
Copy link

mlc-mlapis commented Aug 15, 2023

Yes, I can also confirm that the problem is related to Prettier v3. With Prettier 2.8.8 everything works correctly.

Nx: 16.6.0
Angular: 16.2.0
Prettier: 3.0.1
Windows: 10
NodeJS: 16.14.0

@wanjas
Copy link

wanjas commented Aug 16, 2023

@schmkr Thank you for spotting the cause of the issue!

Exactly the same story for me:
Nx from 16.5.5 to 16.7.0
Prettier: 3.0.1
Linux

Rolling back prettier to 2.8.8 allowed migrations to run with no issues.

@muuvmuuv
Copy link
Contributor

Correct me if I am wrong but NX usually installs its correct peers by itself with nx migrate latest so this is expected to fail, because right now it does not update prettier to 3 but users do manually?

@jotwea
Copy link

jotwea commented Oct 9, 2023

I am not totally sure, but could be that this issue is related to #19207

@maiieul
Copy link

maiieul commented Apr 5, 2024

I was having a similar issue when upgrading to prettier v3 on the qwik-ui cli tests:

  Could not format tsconfig.base.json. Error: "A dynamic import callback was invoked without --experimental-vm-modules"

  15 |
  16 |   tree.write(
> 17 |     fullConfigPath,
     |     ^
  18 |     JSON.stringify({
  19 |       componentsRoot: options.componentsRoot,
  20 |     }),

  at ../../node_modules/.pnpm/@[email protected][email protected]/node_modules/@nx/devkit/src/generators/format-files.js:48:21
      at async Promise.all (index 3)
  at async formatFiles (../../node_modules/.pnpm/@[email protected][email protected]/node_modules/@nx/devkit/src/generators/format-files.js:25:5)
  at async initGenerator (src/generators/init/init-generator.ts:17:5)
  at async Object.<anonymous> (src/generators/init/init-generator.spec.ts:33:9)

Using "test.cli": "NODE_OPTIONS=--experimental-vm-modules nx test cli" seems to have fixed the issue for us.

@FrozenPandaz
Copy link
Collaborator

FrozenPandaz commented May 15, 2024

This was fixed with: #19207

Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

10 participants