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.

Extension doesn't notify user of syntax error in config files

See original GitHub issue

Prettier supports a lot of configuration file names, as noted on the following list, from their docs’ configuration page:

Prettier uses cosmiconfig for configuration file support. This means you can configure prettier via:

  • A .prettierrc file, written in YAML or JSON, with optional extensions: .yaml/.yml/.json/.js.
  • A prettier.config.js file that exports an object.
  • A “prettier” key in your package.json file.

I tried both .prettierrc.js and prettier.config.js. Prettier works as usual, following my configurations, but the extension doesn’t seem to look for either of them, falling back to default settings. It outputs the following message: Failed to resolve config for /home/user/example/file/name.js. Falling back to the default config settings.

Just for context, I’m configuring prettier by javascript to be able to require a template configuration from a npm package.

Does anyone else have had the same issue before? I searched for the error message, but couldn’t find any related issue.

Thanks!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:15 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
ntottencommented, Dec 17, 2019

Version 3.16.0 will now show an error when an invalid configuration file is detected.

1reaction
vhfmagcommented, Aug 6, 2018

Ok, so that’s the part of the code that emits the error message:

const { config: fileOptions, error } = await resolveConfig(fileName, {
    editorconfig: true,
});

if (error) {
    addToOutput(
        `Failed to resolve config for ${fileName}. Falling back to the default config settings.`
    );
}

And that’s resolveConfig definition:

const bundledPrettier = require('prettier') as Prettier;

/**
 * Resolves the prettierconfig for the given file.
 *
 * @param filePath file's path
 */
async function resolveConfig(
    filePath: string,
    options?: { editorconfig?: boolean }
): Promise<ResolveConfigResult> {
    try {
        const config = await bundledPrettier.resolveConfig(filePath, options);
        return { config };
    } catch (error) {
        return { config: null, error };
    }
}

So I tried running prettier.resolveConfig(myFilePath, { editorconfig: true }) just like Prettier VSCode does (with the same prettier version too), but it actually works and resolves the config as expected. I’ll try to debug the extension and see what actually is the value of error.

Read more comments on GitHub >

github_iconTop Results From Across the Web

VSCode does not show syntax errors and Error lens extension ...
Open workspace/folder and select the file from vscode explorer, don't open the file ... Go to the settings and type Error Lens: Enabled...
Read more >
How to Fix the Syntax Error in WordPress - WPBeginner
Use this step by step guide on how to fix the syntax error in WordPress. ... The error will tell you exactly which...
Read more >
Apache Configuration Error AH00526: Syntax error
An Apache AH00526: Syntax error message occurs when there is a typo or misconfigured setting somewhere in your Apache configuration files.
Read more >
21 Examples To Make Sure Unix / Linux Configuration Files ...
Explains how to check your Unix, Linux, *BSD family of operating systems or macOS configuration files for syntax errors and/or warnings.
Read more >
Configuration Files - ESLint - Pluggable JavaScript Linter
JavaScript (ESM) - use .eslintrc.cjs when running ESLint in JavaScript packages that specify "type":"module" in their package.json . Note that ESLint does not...
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