Closed TranquilMarmot closed 4 years ago
Getting the same all the time on macos since recenly, could be related to bumping VSCode to 1.41.0
I have changed my current node version to 10.17.0 and the prettier vscode extension works!.
I am getting a similar error when I try to format a file.
["INFO" - 7:05:17 PM] Loaded module 'prettier@1.19.1' from '/usr/local/lib/node_modules/prettier'
["INFO" - 7:05:17 PM] Formatting using 'prettier-eslint'
["ERROR" - 7:05:17 PM] Error formatting document.
r is not a function
TypeError: r is not a function
at /Users/tjlang/.vscode/extensions/esbenp.prettier-vscode-3.13.0/dist/extension.js:1:352891
at t.default.safeExecution (/Users/tjlang/.vscode/extensions/esbenp.prettier-vscode-3.13.0/dist/extension.js:1:353582)
at t.default.<anonymous> (/Users/tjlang/.vscode/extensions/esbenp.prettier-vscode-3.13.0/dist/extension.js:1:352865)
at Generator.next (<anonymous>)
at s (/Users/tjlang/.vscode/extensions/esbenp.prettier-vscode-3.13.0/dist/extension.js:1:347571)
["INFO" - 7:05:17 PM] Formatting completed in 48.240989ms.
The last message says "formatting complete" but nothing gets formatted. I just recently noticed this problem as well, up until tonight everything had been working perfectly.
I ran the minified code through source map and this is what I am getting back:
// 1:352891
Maps to ../src/PrettierEditService.ts:352:13 (languageResolver)
if (this.languageResolver.doesParserSupportStylelint(parser)) {
// 1:353582
Maps to ../src/PrettierEditService.ts:406:44 (FormattingResult)
this.statusBarService.updateStatusBar(FormattingResult.Success);
I have changed my current node version to 10.17.0 and the prettier vscode extension works!.
I shouldn't have to downgrade node all the way to 10.17.0
I have changed my current node version to 10.17.0 and the prettier vscode extension works!.
I shouldn't have to downgrade node all the way to 10.17.0
I just provide an alternative workaround or a point of reference to track better the issue, In the meantime, if you have a better solution I will love to know it.
I have changed my current node version to 10.17.0 and the prettier vscode extension works!.
I shouldn't have to downgrade node all the way to 10.17.0
I just provide an alternative workaround or a point of reference to track better the issue, In the meantime, if you have a better solution I will love to know it.
I don't have a better solution, I haven't had time to dig into the source to try to find the issue in the minified code.
I think downgrading node that far will break more dependencies than is worth it is all
Okay I looked into the source code and I am pretty sure the error is coming from the most recent commit 3b2030104a4719779e37e5d8ac000cf46aa6a9b8 here:
I dont think the new ModuleResolver
is returning a moduleInstance
now and when it gets called here it throws the TypeError: r is not a function
https://github.com/prettier/prettier-vscode/blob/69af3e2713c0e0411b0e1deaf18bfd21dca220c1/src/PrettierEditService.ts#L340-L348
I'm also getting this issue today.
["INFO" - 11:36:30] Formatting using 'prettier-eslint'
["ERROR" - 11:36:30] Error formatting document.
r is not a function
TypeError: r is not a function
For now I'm just using this instead
I have changed my current node version to 10.17.0 and the prettier vscode extension works!.
I shouldn't have to downgrade node all the way to 10.17.0
I just provide an alternative workaround or a point of reference to track better the issue, In the meantime, if you have a better solution I will love to know it.
You can downgrade to the previous version (3.12.0) from VSCode which will revert the breaking changes introduced in 3.13.0.
You have to reload the window (or restart VSCode) for the changes to take effect.
Install prettier in your project:
npm install -D prettier
Then will work.
Could somebody provide a project that reproduces this. I am seeing that it looks like it may be impacting tslint prettier integration but also stylelint prettier.
@travislang It could be related, but it should be fine if moduleInstance, in that case, is undefined. It first tries local, then global, then falls back to the bundled prettier. Its certainly possible though that causes the error.
@ntotten π
You can try https://github.com/kachkaev/njt πΈ
I've been working on this project for a couple of weekends and prettier-vscode started crashing in it yesterday after some point. The project uses yarn.
@kachkaev This seems to be working for me. Are you on windows? Could be a windows only bug. I'm not at my windows computer now but i can try to check later.
@ntotten I'm on macOS Catalina 10.15.1 π€
For me, prettier-vscode
works in vscode@v1.41.0
after I've downgraded the extension to v3.12.0
. What you might also find interesting is that kachkaev/njt reproduces #1066 too. Try opening package.json
, adding a space and saving. This message pops out in the bottom-right corner:
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
This can be because I'm using prettier-plugin-packagejson.
@kachkaev Can you paste your prettier output log.
The Failed to load module
error should only happen when prettier
is found in the package.json
but you haven't run npm install or yarn, but I am taking it that you have does those and the module is there, but still it isn't finding it.
@ntotten I am on MacOS 10.14.6. Here are my logs:
["INFO" - 10:53:24 PM] Detected local configuration (i.e. .prettierrc or .editorconfig), VS Code configuration will not be used
["INFO" - 10:53:24 PM] Prettier Options:
{
"filepath": "/Users/tjlang/projects/ledger-app/ledger/sagas/auth.js",
"parser": "babel",
"semi": false,
"trailingComma": "all",
"singleQuote": true,
"printWidth": 100,
"tabWidth": 4
}
["INFO" - 10:53:24 PM] Loaded module 'prettier@1.19.1' from '/usr/local/lib/node_modules/prettier'
["INFO" - 10:53:24 PM] Formatting using 'prettier-eslint'
["ERROR" - 10:53:24 PM] Error formatting document.
r is not a function
TypeError: r is not a function
at /Users/tjlang/.vscode/extensions/esbenp.prettier-vscode-3.13.0/dist/extension.js:1:352891
at t.default.safeExecution (/Users/tjlang/.vscode/extensions/esbenp.prettier-vscode-3.13.0/dist/extension.js:1:353582)
at t.default.<anonymous> (/Users/tjlang/.vscode/extensions/esbenp.prettier-vscode-3.13.0/dist/extension.js:1:352865)
at Generator.next (<anonymous>)
at s (/Users/tjlang/.vscode/extensions/esbenp.prettier-vscode-3.13.0/dist/extension.js:1:347571)
["INFO" - 10:53:24 PM] Formatting completed in 53.787154ms.
The strange thing is source map is mapping the r is not a function
to this
Maps to ../src/PrettierEditService.ts:352:13 (languageResolver)
if (this.languageResolver.doesParserSupportStylelint(parser)) {
But clearly from looking at the log Formatting using 'prettier-eslint'
it isn't running the stylelint prettier
so I don't really know....
I have similar output. Steps:
yarn install
vscode@1.41.0
, prettier-vscode@3.13.0
)next.config.js
["INFO" - 17:34:32] Extension Name: "prettier-vscode". ["INFO" - 17:34:32] Extension Version: "3.13.0". ["INFO" - 17:34:32] Loaded module 'prettier@1.19.1' from '/Users/ak/-/projects/kachkaev/oss/njt/node_modules/prettier/index.js' ["INFO" - 17:34:32] Enabling prettier for languages [ "css", "graphql", "html", "javascript", "javascriptreact", "json", "json5", "jsonc", "less", "markdown", "mdx", "mongo", "postcss", "scss", "typescript", "typescriptreact", "vue", "yaml" ] ["INFO" - 17:34:32] Enabling prettier for range supported languages [ "graphql", "javascript", "javascriptreact", "json", "typescript", "typescriptreact" ] ["INFO" - 17:34:35] Loaded module 'prettier@1.19.1' from '/Users/ak/-/projects/kachkaev/oss/njt/node_modules/prettier/index.js' ["INFO" - 17:34:39] Formatting /Users/ak/-/projects/kachkaev/oss/njt/next.config.js ["INFO" - 17:34:39] Loaded module 'prettier@1.19.1' from '/Users/ak/-/projects/kachkaev/oss/njt/node_modules/prettier/index.js' ["INFO" - 17:34:39] Using ignore file (if present) at /Users/ak/-/projects/kachkaev/oss/njt/.prettierignore ["INFO" - 17:34:39] File Info: { "ignored": false, "inferredParser": "babel" } ["INFO" - 17:34:39] Detected local configuration (i.e. .prettierrc or .editorconfig), VS Code configuration will not be used ["INFO" - 17:34:39] Prettier Options: { "filepath": "/Users/ak/-/projects/kachkaev/oss/njt/next.config.js", "parser": "babel", "arrowParens": "always", "endOfLine": "lf", "trailingComma": "all" } ["INFO" - 17:34:40] Loaded module 'prettier@1.18.2' from '/usr/local/lib/node_modules/prettier' ["INFO" - 17:34:40] Formatting using 'prettier-eslint' ["ERROR" - 17:34:40] Error formatting document. r is not a function TypeError: r is not a function at /Users/ak/.vscode/extensions/esbenp.prettier-vscode-3.13.0/dist/extension.js:1:352891 at t.default.safeExecution (/Users/ak/.vscode/extensions/esbenp.prettier-vscode-3.13.0/dist/extension.js:1:353582) at t.default.(/Users/ak/.vscode/extensions/esbenp.prettier-vscode-3.13.0/dist/extension.js:1:352865) at Generator.next ( ) at s (/Users/ak/.vscode/extensions/esbenp.prettier-vscode-3.13.0/dist/extension.js:1:347571) ["INFO" - 17:34:40] Formatting completed in 349.554412ms.
It's unusual to see mentions of prettier 1.18.2, which is installed globally.
UPD: Running npm rm --global prettier
brings the latest version of the extension back to life:
["INFO" - 17:41:03] Extension Name: "prettier-vscode". ["INFO" - 17:41:03] Extension Version: "3.13.0". ["INFO" - 17:41:03] Loaded module 'prettier@1.19.1' from '/Users/ak/-/projects/kachkaev/oss/njt/node_modules/prettier/index.js' ["INFO" - 17:41:03] Loaded module 'prettier@1.19.1' from '/Users/ak/-/projects/kachkaev/oss/njt/node_modules/prettier/index.js' ["INFO" - 17:41:03] Enabling prettier for languages [ "css", "graphql", "html", "javascript", "javascriptreact", "json", "json5", "jsonc", "less", "markdown", "mdx", "mongo", "postcss", "scss", "typescript", "typescriptreact", "vue", "yaml" ] ["INFO" - 17:41:03] Enabling prettier for range supported languages [ "graphql", "javascript", "javascriptreact", "json", "typescript", "typescriptreact" ] ["INFO" - 17:41:10] Loaded module 'prettier@1.19.1' from '/Users/ak/-/projects/kachkaev/oss/njt/node_modules/prettier/index.js' ["INFO" - 17:41:14] Loaded module 'prettier@1.19.1' from '/Users/ak/-/projects/kachkaev/oss/njt/node_modules/prettier/index.js' ["INFO" - 17:41:17] Formatting /Users/ak/-/projects/kachkaev/oss/njt/next.config.js ["INFO" - 17:41:17] Loaded module 'prettier@1.19.1' from '/Users/ak/-/projects/kachkaev/oss/njt/node_modules/prettier/index.js' ["INFO" - 17:41:17] Using ignore file (if present) at /Users/ak/-/projects/kachkaev/oss/njt/.prettierignore ["INFO" - 17:41:17] File Info: { "ignored": false, "inferredParser": "babel" } ["INFO" - 17:41:17] Detected local configuration (i.e. .prettierrc or .editorconfig), VS Code configuration will not be used ["INFO" - 17:41:17] Prettier Options: { "filepath": "/Users/ak/-/projects/kachkaev/oss/njt/next.config.js", "parser": "babel", "arrowParens": "always", "endOfLine": "lf", "trailingComma": "all" } ["INFO" - 17:41:18] Formatting completed in 412.703647ms.
@ntotten I think the issue is that the new update is somehow forcing the extension to load the global package, look at these logs:
// here it finds and loads the local prettier module
["INFO" - 12:20:09 PM] Loaded module 'prettier@1.19.1' from '/Users/tjlang/projects/ledger-app/ledger/node_modules/prettier/index.js'
["INFO" - 12:20:19 PM] Formatting /Users/tjlang/projects/ledger-app/ledger/sagas/auth.js
["INFO" - 12:20:19 PM] Loaded module 'prettier@1.19.1' from '/Users/tjlang/projects/ledger-app/ledger/node_modules/prettier/index.js'
["INFO" - 12:20:19 PM] Using ignore file (if present) at /Users/tjlang/projects/ledger-app/ledger/.prettierignore
["INFO" - 12:20:19 PM] File Info:
{
"ignored": false,
"inferredParser": "babel"
}
["INFO" - 12:20:19 PM] Detected local configuration (i.e. .prettierrc or .editorconfig), VS Code configuration will not be used
["INFO" - 12:20:19 PM] Prettier Options:
{
"filepath": "/Users/tjlang/projects/ledger-app/ledger/sagas/auth.js",
"parser": "babel",
"semi": false,
"trailingComma": "all",
"singleQuote": true,
"printWidth": 100,
"tabWidth": 4
}
// now here it loads the global prettier module
["INFO" - 12:20:19 PM] Loaded module 'prettier@1.19.1' from '/usr/local/lib/node_modules/prettier'
["INFO" - 12:20:19 PM] Formatting using 'prettier-eslint'
["ERROR" - 12:20:19 PM] Error formatting document.
It initially finds the local package but after getting all of the configs it loads the global package.
The fix for now is to run npm rm -g prettier
like @kachkaev mentioned. This forces the extension to use the local package and it then formats correctly.
So somehow it is trying to load the global package and returning undefined somewhere even if the local package exists...
I think i fixed it, try updating to 3.14.0. I accidentally left a hard-coded string in that was supposed to be a variable. See: https://github.com/prettier/prettier-vscode/blob/69af3e2713c0e0411b0e1deaf18bfd21dca220c1/src/ModuleResolver.ts#L148
Not sure how tests didn't get this. I need to investigate, but don't have time right now. My wife gave birth to our second kid last night so just doing a bit of work while they are both sleeping. ;)
Let me at least know that this fixed the problem.
@ntotten I reinstalled prettier globally and reproduced the bug in prettier-vscode@3.13.0
again. After upgrading to prettier-vscode@3.14.0
and reloading VSCode, the error disappeared π
All works, many thanks for your quick reaction and for cutting a new release! π
Great. I'm going to leave this open so I can write some tests later, but glad it is working again.
@ntotten Same thing for me, reinstalled globally, 3.13 still had the issue, upgraded to 3.14 and the problem was solved. Thanks for fixing quickly and congrats on the second child! π
osx 10.15, vscode 1.41.0 - upgrade from prettier-vscode 3.13.0 to 3.14.0 and it looks like prettier is working again. thanks @ntotten and congrats! πΌπΆπ
@ntotten Fixed as well here with 3.14.0 on VSCode 1.41.0. Thanks for a quick release and congratulations ! π
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.
Summary
When running Prettier in VSCode, the following exception is thrown:
This happens with both auto-format on save and when running the format command.
VS Code Version:
Prettier Extension Version:
OS and version:
Windows 10