question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

When "prettier.requireConfig" is true and no config exists extension should not try to load Prettier

See original GitHub issue

Issue Type: Bug

Hey there, in a particular scenario the extension is constantly giving me these error notifications with the following message:

Failed to load module. If you have prettier or plugins referenced in package.json, ensure you have run npm install Attempted to load prettier from package.json

The folder I’ve opened in Code is a subdirectory of a project (an example in the examples folder of https://github.com/zeit/next.js) where the root project has prettier listed in package.json but the example project does not. That’s maybe fair – I can see why you might want to recurse up to find the first relevant package.json.

But more notably, I have prettier.requireConfig set to true in my user settings, and as far as I can see neither the example subproject nor the root project has a .prettierrc or a Prettier config in its package.json. I don’t want to install the root project (which has a huge number of dependencies and takes a long time) to make a simple fix to an example, so Prettier indeed isn’t installed – but why should the extension scream about it not being installed in the first place, when I’ve told it to do nothing unless it finds a config?


Relevant parts of my user settings.json

{
  "editor.formatOnSave": true,
  "prettier.disableLanguages": [
    "markdown",
    "json",
    "jsonc",
    "plaintext"
  ],
  "prettier.requireConfig": true,
  "[json],[jsonc]": {
    "editor.defaultFormatter": "vscode.json-language-features"
  },
  "[javascript]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "[javascriptreact]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  }
}

The subproject package.json in question:

{
  "name": "with-react-intl",
  "version": "1.0.0",
  "scripts": {
    "start": "NODE_ENV=production node --icu-data-dir=node_modules/full-icu server.js",
    "dev": "node --icu-data-dir=node_modules/full-icu server.js",
    "build": "next build && npm run extract && node ./scripts/default-lang",
    "extract": "formatjs extract --messages-dir lang/.messages/ --remove-default-message pages/*.js"
  },
  "dependencies": {
    "@formatjs/cli": "1.1.12",
    "@formatjs/intl-relativetimeformat": "^2.8.2",
    "@formatjs/intl-utils": "^0.6.1",
    "accepts": "^1.3.7",
    "full-icu": "^1.3.0",
    "glob": "^7.1.4",
    "intl": "^1.2.5",
    "next": "latest",
    "react": "^16.9.0",
    "react-dom": "^16.9.0",
    "react-intl": "^3.1.12"
  },
  "license": "ISC"
}

The result of running $ npm ls -g --depth=0:

/home/whatever/.nvm/versions/node/v13.1.0/lib
├── npm@6.13.0
└── typescript@3.7.2

The error stack I’m getting over and over in VSCode:

["ERROR" - 2:22:53 p.m.] Failed to load prettier from ''
Cannot find module 'prettier' from '/home/whatever/project/package.json'
Error: Cannot find module 'prettier' from '/home/whatever/project/package.json'
	at Function.e.exports [as sync] (/home/whatever/.vscode/extensions/esbenp.prettier-vscode-3.18.0/dist/extension.js:1:319843)
	at t.ModuleResolver.findPkg (/home/whatever/.vscode/extensions/esbenp.prettier-vscode-3.18.0/dist/extension.js:1:246852)
	at t.ModuleResolver.findPkg (/home/whatever/.vscode/extensions/esbenp.prettier-vscode-3.18.0/dist/extension.js:1:246954)
	at t.ModuleResolver.findPkg [as findPkgMem] (/home/whatever/.vscode/extensions/esbenp.prettier-vscode-3.18.0/dist/extension.js:1:247210)
	at t.ModuleResolver.requireLocalPkg (/home/whatever/.vscode/extensions/esbenp.prettier-vscode-3.18.0/dist/extension.js:1:245330)
	at t.ModuleResolver.getPrettierInstance (/home/whatever/.vscode/extensions/esbenp.prettier-vscode-3.18.0/dist/extension.js:1:243969)
	at t.LanguageResolver.getSupportLanguages (/home/whatever/.vscode/extensions/esbenp.prettier-vscode-3.18.0/dist/extension.js:1:242420)
	at t.LanguageResolver.allEnabledLanguages (/home/whatever/.vscode/extensions/esbenp.prettier-vscode-3.18.0/dist/extension.js:1:242028)
	at t.StatusBarService.toggleStatusBarItem (/home/whatever/.vscode/extensions/esbenp.prettier-vscode-3.18.0/dist/extension.js:1:85577)
	at /home/whatever/.vscode/extensions/esbenp.prettier-vscode-3.18.0/dist/extension.js:1:85250
	at l.fire (/usr/share/code/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:46:893)
	at /usr/share/code/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:641:245
	at l.fire (/usr/share/code/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:46:893)
	at f.$acceptDocumentsAndEditorsDelta (/usr/share/code/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:561:804)
	at p._doInvokeHandler (/usr/share/code/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:663:275)
	at p._invokeHandler (/usr/share/code/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:662:971)
	at p._receiveRequest (/usr/share/code/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:661:639)
	at p._receiveOneMessage (/usr/share/code/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:660:468)
	at /usr/share/code/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:658:691
	at l.fire (/usr/share/code/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:46:893)
	at _.fire (/usr/share/code/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:189:274)
	at /usr/share/code/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:820:285
	at l.fire (/usr/share/code/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:46:893)
	at _.fire (/usr/share/code/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:189:274)
	at t.PersistentProtocol._receiveMessage (/usr/share/code/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:193:629)
	at /usr/share/code/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:190:824
	at l.fire (/usr/share/code/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:46:893)
	at p.acceptChunk (/usr/share/code/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:186:737)
	at /usr/share/code/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:186:89
	at Socket.t (/usr/share/code/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:195:68)
	at Socket.emit (events.js:200:13)
	at addChunk (_stream_readable.js:294:12)
	at readableAddChunk (_stream_readable.js:275:11)
	at Socket.Readable.push (_stream_readable.js:210:10)
	at Pipe.onStreamRead (internal/stream_base_commons.js:166:17)

Extension version: 3.18.0 VS Code version: Code 1.41.1 (26076a4de974ead31f97692a0d32f90d735645c0, 2019-12-18T15:04:31.999Z) OS version: Linux x64 4.15.0-72-generic

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
ntottencommented, Dec 24, 2019

Good point, will fix shortly.

0reactions
github-actions[bot]commented, Jul 21, 2020

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

VSCode Prettier not respecting Require Config option for ...
I would like to configure the Visual Studio Code Prettier extension to automatically format on save, but only if a .prettierrc file exists...
Read more >
Self-Hosted configuration options - Renovate Docs
Set to true to allow templating of dependency level post-upgrade commands. Let's look at an example of configuring packages with existing Angular migrations....
Read more >
jlongster/prettier - Gitter
I'm new to prettier and I run to the problem with formatting my async / await functions. In eslint configuration I have this...
Read more >
CodeMirror 5 User Manual
It will automatically load the modes that the mixed HTML mode depends on (XML, JavaScript, and CSS). Do not use RequireJS' paths option...
Read more >
How to configure Prettier and VSCode - Gleb Bahmutov
and can be added to your project .eslintrc.json file. ESLint will not run without a valid configuration file. 1 2
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found