idahogurl / vs-code-prettier-eslint

A Visual Studio Code Extension to format JavaScript and TypeScript code using the prettier-eslint package.
MIT License
184 stars 46 forks source link

Extension cannot resolve globally installed prettier-eslint #216

Closed aminomancer closed 3 weeks ago

aminomancer commented 4 months ago

Describe the bug With the 6.0 update, the extension is no longer working in any repositories where prettier-eslint is not installed locally, even though I have it installed globally. I also tried reinstalling it and switching node/npm versions, to no avail. This is troubling for me since I work on very large repositories with already established workflows, so I can't just add prettier-eslint to every package I work on. So I've had to use an old version of the extension, even though the newer version works on my other repos.

I'm thinking this is unexpected behavior because the readme says:

This extension requires the following NPM packages to be installed either locally or globally:

  • prettier-eslint@^16.1.2

To Reproduce Not sure about STR, just starting vscode I immediately see the following:

Error: Could not warm up worker. Formatting a file for the first time may take longer than usual.
Message: Cannot find module 'prettier-eslint'
Require stack:
- c:\Users\shmed\.vscode\extensions\rvest.vs-code-prettier-eslint-6.0.0\dist\extension.js
- c:\Users\shmed\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\loader.js
- c:\Users\shmed\AppData\Local\Programs\Microsoft VS Code\resources\app\out\bootstrap-amd.js
- c:\Users\shmed\AppData\Local\Programs\Microsoft VS Code\resources\app\out\bootstrap-fork.js

The module is definitely installed and working for all other purposes:

$ npm list -g
C:\Program Files\nodejs -> .\
├── @typescript-eslint/parser@5.0.1-alpha.22+6746b8cc
├── corepack@0.12.1
├── eslint@8.52.0
├── npm@8.15.0
├── prettier-eslint@16.1.2
├── prettier@3.1.0
├── typescript@4.4.4
└── yarn@1.22.19

I'm using nvm-windows but I also tried a standard npm installation.

Expected behavior Extension should be able to find global modules

Example Project This is happening with all projects, until I install prettier-eslint locally in them. I first noticed it on mozilla-central but I'm getting the same issue everywhere, e.g. here's a simple example.

Versions (please complete the following information):

System Specifications (please complete the following information):

Additional context I assume module resolution problems have more to do with my environment than anything else, so let me know if there are any logs I can provide that would help with debugging.

I haven't looked at the extension's source code, but this is the same error you'll see when you try to import a global module without first linking it, so I wonder if the extension is just naively importing prettier-eslint and assuming it will resolve as normal. But I don't know how you could practically link a global module to a vscode extension.

This might be the same issue as #197. It seems that one was closed automatically without resolution.

TargiX commented 4 months ago

Same issue here, Macos, Sonoma

wanderBee commented 4 months ago

Same issue here

Kuro091 commented 4 months ago

Same issue, was going crazy over this!

laholstege commented 4 months ago

same issue on mac sonoma

CoLdAs1cE commented 4 months ago

same :(

Marckon commented 4 months ago

https://stackoverflow.com/questions/55771578/cant-find-the-module-after-extension-is-installed

cd ~/.vscode/extensions
cd your.extension
npm install

should work. (I am not sure if this is a bug of this extension or vscode itself, as I didn't encounter this before updating vscode to its latest version.)

aminomancer commented 4 months ago

stackoverflow.com/questions/55771578/cant-find-the-module-after-extension-is-installed

cd ~/.vscode/extensions
cd your.extension
npm install

should work.

I suppose it's better than rolling back, but I would still prefer if the extension can just find the global modules so we don't have to reinstall node modules every time the extension updates.

(I am not sure if this is a bug of this extension or vscode itself, as I didn't encounter this before updating vscode to its latest version.)

I feel like extensions should at least be able to locate global modules if the NODE_PATH environment variable is set, the way a script running in node can normally do regardless of where it's running. So there may very well be a vscode bug, although I have encountered this issue on both the latest prod version of vscode and the previous one.

acron0 commented 3 months ago

https://stackoverflow.com/questions/55771578/cant-find-the-module-after-extension-is-installed

cd ~/.vscode/extensions
cd your.extension
npm install

should work. (I am not sure if this is a bug of this extension or vscode itself, as I didn't encounter this before updating vscode to its latest version.)

This worked for me, although a little trickier to find as I am using Codespaces. For me the dir was /home/codespace/.vscode-remote/extensions/rvest.vs-code-prettier-eslint-6.0.0

github-actions[bot] commented 2 months ago

This issue is stale because it has been open for 14 days with no activity.

github-actions[bot] commented 2 months ago

This issue was closed because it has been inactive for 14 days since being marked as stale.

aminomancer commented 2 months ago

@idahogurl Is there any chance this can be fixed? Thanks.

github-actions[bot] commented 1 month ago

This issue is stale because it has been open for 14 days with no activity.

github-actions[bot] commented 3 weeks ago

This issue was closed because it has been inactive for 14 days since being marked as stale.