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

Problems with @prettier/sync #150

Closed
TonyGravagno opened this issue Aug 29, 2024 · 1 comment
Closed

Problems with @prettier/sync #150

TonyGravagno opened this issue Aug 29, 2024 · 1 comment

Comments

@TonyGravagno
Copy link
Collaborator

TonyGravagno commented Aug 29, 2024

I'm describing an issue below that is caused by dependencies. When the issues in the dependencies are resolved, this issue can be closed, as it will no longer be an issue for users of this package.


This project currently uses @prettier/sync v0.3.0 and prettier 3.0.3.

With this configuration I was getting occasional aborts with "Uncaught Error Error: Cannot find module './worker.js'" ?

Here is a simplified return stack:

at createWorker (...\node_modules\.pnpm\@[email protected][email protected]\node_modules\@prettier\sync\index.cjs:44:25)
at formatByPrettier (...\src\process\formatByPrettier.ts:4:11)
at outputToFile (...\src\process\outputToFile.ts:18:20)

So, in outputToFile, the code is used to synchronously reformat the schema and global schema files before they are written.

Here is another warning when the project starts:

esbuild ./src/main.ts --bundle --sourcemap --platform=node --outfile=./dist/main.js
▲ [WARNING] "./worker.js" should be marked as external for use with "require.resolve" [require-resolve-not-external]

node_modules/.pnpm/@ [email protected][email protected]/node_modules/@ prettier/sync/index.cjs:44:40:
44 │ worker = new Worker(require.resolve("./worker.js"));

While a missing file should be a critical issue, it seems an error only occurs if bad code that is sent to the prettier process, which can happen during our development.

The code in @prettier/sync was re-written. v0.5.2 is now very different and that specific error is gone.

However, there is a new issue, in that new version, and ONLY when this project is run in debug mode. The debugger will lock on a semaphore during initialization and will therefore not execute the main.js code here that does the schema generation.

Summary :

  1. With @prettier/sync 0.3.0 specified in package.json, when not running in debug, and when generated code is good, there is no problem other than warnings.
  2. With 0.3.0 a failure only occurs if we are generating bad code in schema.ts or in globalSchema.ts.
  3. The issue is not in "prettier", it is in this other extension that makes prettier run synchronously.
  4. This project should not update to v0.5.2 yet. In addition to the issues noted here, the way that this synchronized Prettier is used has changed - noted in fix: Changes required for @prettier/sync v0.5.2 #151.
@araera111
Copy link
Owner

I've updated the code to no longer use @prettier/sync, so I'll be closing this issue now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants