-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
NodeJS API: Changes to .js config not being picked up due to NodeJS module caching #5311
Copy link
Copy link
Closed
Copy link
Labels
area:apiIssues with Prettier's Application Programming InterfaceIssues with Prettier's Application Programming Interfacelocked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.Please open a new issue and fill out the template instead of commenting.scope:dependencyIssues that cannot be solved inside Prettier itself, and must be fixed in a dependencyIssues that cannot be solved inside Prettier itself, and must be fixed in a dependencystatus:has prIssues with an accompanying pull request. These issues will probably be fixed soon!Issues with an accompanying pull request. These issues will probably be fixed soon!
Milestone
Metadata
Metadata
Assignees
Labels
area:apiIssues with Prettier's Application Programming InterfaceIssues with Prettier's Application Programming Interfacelocked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.Please open a new issue and fill out the template instead of commenting.scope:dependencyIssues that cannot be solved inside Prettier itself, and must be fixed in a dependencyIssues that cannot be solved inside Prettier itself, and must be fixed in a dependencystatus:has prIssues with an accompanying pull request. These issues will probably be fixed soon!Issues with an accompanying pull request. These issues will probably be fixed soon!
Environments:
Steps to reproduce:
This is reproducible via any Prettier editor integration, e.g. prettier-vscode or Intellij prettier plugin:
tabWidthto 2Expected behavior:
File is reformatted with the new tabWidth (2).
Actual behavior:
File is reformatted with the previous tabWidth (7), until the editor is restarted. After that the file is reformatted with new settings.
With
prettierversion 1.13.7 the changes to the file are picked up correctly.Same with .json or .yaml config files - changes are picked up immediately after changing the config file.
This seems to be caused by the fact that Node.js
requirecaches the loaded modules for the duration of the process. Editor integrations usually create a long-running process that then invokes 'reformat' multiple times, so if the config is read viarequire, subsequent attempts to read it will return the same result.Prettier updated
cosmiconfigto version 5 here, in 1.14.1.Cosmiconfig replaced
require-from-stringwith plainrequirehere.require-from-stringhad the side effect of not caching the loaded modules.ESLint had a similar issue in the past: eslint/eslint#5067 and addressed it by using
require-uncached.Even though this mostly affects editor integrations, I believe this should be addressed in
prettieritself (or possibly incosmiconfig), and not in editor integrations because:prettierpicks up changes correctly for *.json or *.yaml files