简体   繁体   English

错误:EACCES:权限被拒绝,mkdir '/usr/local/lib/node_modules/node-sass/build'

[英]Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/node-sass/build'

I am trying to run an Angular application.我正在尝试运行 Angular 应用程序。 I execute the ng serve command, but it then shows:我执行ng serve命令,但随后显示:

Error: Cannot find module 'node-sass'错误:找不到模块“node-sass”

Solution:解决方案:

You need to change the ownership of folder node_modules , because you use sudo npm install -g node-sass , so its ownership is set to root.您需要更改文件夹node_modules的所有权,因为您使用sudo npm install -g node-sass ,所以它的所有权设置为 root。

To change the ownership to the current user as group -要将所有权更改为当前用户作为组 -

sudo chown -R root:$(whoami) /usr/local/lib/node_modules/

sudo chmod -R 775 /usr/local/lib/node_modules/

And never use sudo for an npm -related query.并且永远不要将sudo用于与npm相关的查询。

运行此命令

sudo npm install -g <ModuleName> --unsafe-perm=true --allow-root

Try this尝试这个

sudo npm install -g --unsafe-perm node-sass sudo npm install -g --unsafe-perm node-sass

Or this或这个

sudo npm install -g --unsafe-perm --verbose @angular/cli sudo npm install -g --unsafe-perm --verbose @angular/cli

I was working in Ionic and had this issue, so I solved this by moving one folder back and running this command:我在Ionic工作并遇到了这个问题,所以我通过移动一个文件夹并运行以下命令来解决这个问题:

sudo chmod -R 777 project-directory

And after this:在此之后:

npm install node-sass --save

This is due to the user's permission.这是由于用户的许可。 The user from which you are running the command of npm install is probably doesn't have permission.您运行npm install命令的用户可能没有权限。 So you are getting errors.所以你得到了错误。

For that user just give the permission for that project folder.对于该用户,只需授予该项目文件夹的权限。 In Mac , use the below steps and give read and write permission to the user for that project folderMac中,使用以下步骤并授予用户对该项目文件夹的读取和写入权限

  • On your Mac, select a disk, folder, or file, and then choose menu FileGet Info .在 Mac 上,选择磁盘、文件夹或文件,然后选择菜单FileGet Info

  • If the information in Sharing & Permissions isn't visible, click the arrow.如果共享和权限中的信息不可见,请单击箭头。

  • If the lock at the bottom right is locked, click it to unlock the Get Info options, and then enter an administrator name and password.如果右下角的锁被锁定,单击它以解锁“获取信息”选项,然后输入管理员名称和密码。

  • Click a user or group in the Name column, and then choose a privilege setting from the pop-up menu.单击名称列中的用户或组,然后从弹出菜单中选择权限设置。

    • Read & Write: Allows a user to open the item and change it.读写:允许用户打开项目并进行更改。

    • Read-only: This allows a user to open the item but not change its contents.只读:这允许用户打开项目但不能更改其内容。

    • Write only (Drop Box): Makes a folder into a drop box.只写(投递箱):使文件夹成为投递箱。 Users can copy items to the drop box, but can't open it.用户可以将项目复制到投递箱,但不能将其打开。 Only the owner of the dropbox can open it.只有保管箱的所有者才能打开它。

    • No Access: Blocks all access to the item.无权访问:阻止对该项目的所有访问权。

This helped me to solve the problem.这帮助我解决了问题。

This worked for me -这对我有用 -

sudo chown -R `whoami` ~/.npm
sudo chown -R `whoami` /usr/local/lib/node_modules

If you have not added Node.js pakage.json yet, try running node init .如果您尚未添加 Node.js pakage.json ,请尝试运行node init If you already have this, npm install node-sass .如果你已经有了这个, npm install node-sass

If both are present and you are using Ubuntu , try changing the permission of the folder using chmod -R <path to node module> .如果两者都存在并且您使用的是Ubuntu ,请尝试使用chmod -R <path to node module>更改文件夹的权限。

Try this: npm install node-sass@version试试这个: npm install node-sass@version

If you want the latest, then just try npm install node-sass .如果你想要最新的,那么试试npm install node-sass

If you're getting an access problem then:如果您遇到访问问题,那么:

  1. Windows: command prompt in administrator mode, and then run the above. Windows:管理员模式下的命令提示符,然后运行上面的。

  2. Mac:苹果电脑:

     sudo npm install node-sass

References参考

Make sure you are not in the home directory or other places.确保您不在目录或其他位置。 You need to go back to root.你需要回到根目录。

Use this command使用此命令

cd ..
cd ~

Your current location should look like:您当前的位置应如下所示:

~$

After this, run the command to create a project.在此之后,运行命令来创建一个项目。

u need to use a "root" user in your shell,你需要在你的shell中使用“root”用户,

with this command:使用此命令:

sudo su -须藤苏-

then you should enter your password那么你应该输入你的密码

and then try to install the package, i think it will work with any package that you try to install globally然后尝试安装该软件包,我认为它可以与您尝试全局安装的任何软件包一起使用

more info that help me in this website在这个网站上对我有帮助的更多信息

http://www.dark-hamster.com/programming/how-to-solve-error-message-eacces-permission-denied-in-nodejs-application/ http://www.dark-hamster.com/programming/how-to-solve-error-message-eacces-permission-denied-in-nodejs-application/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 EACCES:权限被拒绝,在 ubuntu 上运行 npm install 时 mkdir &#39;/node_modules/node-sass/build&#39; - EACCES: permission denied, mkdir '/node_modules/node-sass/build' while running npm install on ubuntu 吉普错误! 堆栈错误:EACCES:权限被拒绝,mkdir &#39;/var/www/project_name/node_modules/node-sass/build&#39; - gyp ERR! stack Error: EACCES: permission denied, mkdir '/var/www/project_name/node_modules/node-sass/build' EACCES:权限被拒绝,mkdir &#39;/usr/local/lib/node_modules/react-native-cli&#39; - EACCES: permission denied, mkdir '/usr/local/lib/node_modules/react-native-cli' NPM Mac OS 错误:EACCES:权限被拒绝,访问“/usr/local/lib/node_modules” - NPM Mac OS error: EACCES: permission denied, access '/usr/local/lib/node_modules' 错误:EACCES:权限被拒绝,访问'/usr/local/lib/node_modules/ANGULAR - ERROR: EACCES: permission denied, access '/usr/local/lib/node_modules/ ANGULAR 错误:EACCES:权限被拒绝,访问'/usr/local/lib/node_modules' - Error: EACCES: permission denied, access '/usr/local/lib/node_modules' Npm 错误“错误:EACCES:权限被拒绝,mkdir &#39;../node-sass/build&#39;” - Npm error "Error: EACCES: permission denied, mkdir '../node-sass/build'" EACCES:权限被拒绝,打开'/usr/local/lib/node_modules/npm/bin/npm-cli.js' - EACCES: permission denied, open '/usr/local/lib/node_modules/npm/bin/npm-cli.js' 内部错误:EACCES:权限被拒绝,符号链接 '../lib/node_modules/corepack/dist/pnpm.js' -&gt; '/usr/local/bin/pnpm' - Internal Error: EACCES: permission denied, symlink '../lib/node_modules/corepack/dist/pnpm.js' -> '/usr/local/bin/pnpm' 如何修复此错误“gyp ERR:堆栈错误:EACCES,权限被拒绝,mkdir '/home/mohamedessam/Desktop/NodeJs/node_modules/bcrypt/build'” - How to fix this error "gyp ERR! stack Error: EACCES: permission denied, mkdir '/home/mohamedessam/Desktop/NodeJs/node_modules/bcrypt/build'"
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM