Closed victorkiko98 closed 2 years ago
Thanks @victorkiko98 for reporting. This link might help if you keep running into EACCES errors
@victorkiko98 It isn't strictly necessary - prettier simply makes your code easier to read (you run it and your code gets formatted to be more readable).
This is a permissions error. If you're using Ubuntu Linux you'll get this often - and I suspect that people who work with Linux a lot understand all the tips and tricks to get around it. I further suspect that documentation authors assume that if you have chosen to use Linux you're one of those people who can google yourself out of trouble.
On a personal level, I use linux in a VM on Windows. That means I can't break anything so I will cheat. To overcome a problem like this I run all the commands in sudo
which gives elevated privileges. You would not do this on a real computer (apparently). I'd also highly recommend installing nvm for managing different versions of node - it won't matter when you get started, but you'll thank me for that advice later.
OK, I have attempted to fix this with https://github.com/mdn/content/pull/14673. I don't see much choice given this is Learn material - though I have tried to point to the fact that there are potential risks.
So an update; On the next articles it says for me to use Prettier, so I tried again but it gave the same error but this time I typed in: npx prettier And it seemed to have worked since it gave this message ... below. Just thought I should let somebody know.
... 1234567890-QWERTYUIOPasdfghjklZXCVBNMasdfghjkls-MacBook-Air:~ victorrafael$ npx prettier Need to install the following packages: prettier Ok to proceed? (y) y Usage: prettier [options] [file/dir/glob ...]
By default, output is written to stdout. Stdin is read if it is piped to Prettier and no files are given.
Output options:
-c, --check Check if the given files are formatted, print a human-friendly summary message and paths to unformatted files (see also --list-different). -l, --list-different Print the names of files that are different from Prettier's formatting (see also --check). -w, --write Edit files in-place. (Beware!)
Format options:
--arrow-parens <always|avoid>
Include parentheses around a sole arrow function parameter.
Defaults to always.
--bracket-same-line Put > of opening tags on the last line instead of on a new line.
Defaults to false.
--no-bracket-spacing Do not print spaces between brackets.
--embedded-language-formatting <auto|off>
Control how Prettier formats quoted code embedded in the file.
Defaults to auto.
--end-of-line <lf|crlf|cr|auto>
Which end of line characters to apply.
Defaults to lf.
--html-whitespace-sensitivity <css|strict|ignore>
How to handle whitespaces in HTML.
Defaults to css.
--jsx-single-quote Use single quotes in JSX.
Defaults to false.
--parser <flow|babel|babel-flow|babel-ts|typescript|acorn|espree|meriyah|css|less|scss|json|json5|json-stringify|graphql|markdown|mdx|vue|yaml|glimmer|html|angular|lwc>
Which parser to use.
--print-width
Config options:
--config --plugin
s.
Defaults to [].
--plugin-search-dir
Editor options:
--cursor-offset
Other options:
--no-color Do not colorize error messages.
--no-error-on-unmatched-pattern
Prevent errors when pattern is unmatched.
--file-info
In this article ... , it says to install Prettier with: "npm install prettier -g" and that resulted in error messages but when I inputted: "npm install prettier" no errors showed up, but that also may be because I already installed it by inputting "npx prettier".
1234567890-QWERTYUIOPasdfghjklZXCVBNMasdfghjkls-MacBook-Air:~ victorrafael$ npm install prettier -g npm ERR! code EACCES npm ERR! syscall mkdir npm ERR! path /usr/local/lib/node_modules/prettier npm ERR! errno -13 npm ERR! Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/prettier' npm ERR! [Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/prettier'] { npm ERR! errno: -13, npm ERR! code: 'EACCES', npm ERR! syscall: 'mkdir', npm ERR! path: '/usr/local/lib/node_modules/prettier' npm ERR! } npm ERR! npm ERR! The operation was rejected by your operating system. npm ERR! It is likely you do not have the permissions to access this file as the current user npm ERR! npm ERR! If you believe this might be a permissions issue, please double-check the npm ERR! permissions of the file and its containing directories, or try running npm ERR! the command again as root/Administrator.
npm ERR! A complete log of this run can be found in: npm ERR! /Users/victorrafael/.npm/_logs/2022-04-07T16_49_50_419Z-debug-0.log 1234567890-QWERTYUIOPasdfghjklZXCVBNMasdfghjkls-MacBook-Air:~ victorrafael$ npm install prettier
up to date, audited 2 packages in 581ms
1 package is looking for funding
run npm fund
for details
found 0 vulnerabilities 1234567890-QWERTYUIOPasdfghjklZXCVBNMasdfghjkls-MacBook-Air:~ victorrafael$
@victorkiko98 Just be aware that you still need to fix your version - installing using npx in that way does not do that. For more information see: https://prettier.io/docs/en/install.html
I'm sorry, I'm still confused. So in the link it says to input: "npm install --save-dev --save-exact prettier" and: "echo {}> .prettierrc.json" but when I have done that when I check to see if I have installed it globally, as said in the article, with "prettier -v" it says "command not found".
So from here to here I tried to install nvm by inputting: "curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash" and it seemed to work but when I try to input $ nvm use 9 or $ nvm use 16, etc. it says "-bash: nvm: command not found". The other option I haven't tried yet is Manually change npm's default directory
@victorkiko98 Thanks.
You might want to look at the fixed up docs in https://github.com/mdn/content/pull/14673
You will note that these removed "npm install --save-dev --save-exact prettier"
and: "echo {}> .prettierrc.json"
from the updated docs because neither of them are needed to install it locally.
The docs no longer install globally, so you can't do prettier -v
- the system doesn't know "globally" what prettier is any more.
You would have to do npx prettier -v
. That says "run this particular local package"
Getting NVM to work is a different problem. What version of Ubuntu are you running this on, and is it "clean"? The most likely guess is that you haven't shut down your terminal and reloaded it. After running that curl command everything is set up, but it isn't applied for that current terminal.
MDN URL: https://developer.mozilla.org/en-US/docs/Learn/Tools_and_testing/Understanding_client-side_tools/Command_line
What information was incorrect, unhelpful, or incomplete?
I downloaded the latest 17.8.0 Current Node.js from the link they referenced, and from there they said to install Prettier by inputting this command on the terminal: npm install --global prettier
Instead of installing and running it gave this error: npm ERR! code EACCES npm ERR! syscall mkdir npm ERR! path /usr/local/lib/node_modules/prettier npm ERR! errno -13 npm ERR! Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/prettier' npm ERR! [Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/prettier'] { npm ERR! errno: -13, npm ERR! code: 'EACCES', npm ERR! syscall: 'mkdir', npm ERR! path: '/usr/local/lib/node_modules/prettier' npm ERR! } npm ERR! npm ERR! The operation was rejected by your operating system. npm ERR! It is likely you do not have the permissions to access this file as the current user npm ERR! npm ERR! If you believe this might be a permissions issue, please double-check the npm ERR! permissions of the file and its containing directories, or try running npm ERR! the command again as root/Administrator.
npm ERR! A complete log of this run can be found in: npm ERR! /Users/victorrafael/.npm/_logs/2022-04-01T15_09_30_948Z-debug-0.log
I tried downloading the older 16.14.2 LTS Node.js and tried the same thing but it gave the same error. I'm a complete beginner with the command line and only know web development from the beginning of the "Learn web development" guide to up to this point. So I really don't know what to do or understand what people are saying when I copied and pasted the error on google.
For now, I guess I'll just skip the Prettier CLI tool introduction and I hope its not too important to the rest of learning web development. Thanks
Specific section or headline?
What did you expect to see?
Did you test this? If so, how?
MDN Content page report details
* Folder: `en-us/learn/tools_and_testing/understanding_client-side_tools/command_line` * MDN URL: https://developer.mozilla.org/en-US/docs/Learn/Tools_and_testing/Understanding_client-side_tools/Command_line * GitHub URL: https://github.com/mdn/content/blob/main/files/en-us/learn/tools_and_testing/understanding_client-side_tools/command_line/index.md * Last commit: https://github.com/mdn/content/commit/c4b6112d856dbb5fa7b929e5034499c605a51e08 * Document last modified: 2022-03-28T14:52:22.000Z