尝试安装聚合物时出现npm错误

时间:2020-05-09 18:02:11

标签: javascript node.js npm polymer

我正在尝试使用html和javascript测试传感器,如图所示here,但是当我尝试安装 polymer 时(如自述文件中所述),出现此错误:

kupu@kupu:~/Dropbox/IOT/generic-sensor-demos/sensor-info$ npm install -g polymer-cli
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules
npm ERR! code EACCES
npm ERR! syscall access
npm ERR! path /usr/local/lib/node_modules
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
npm ERR!  { [Error: EACCES: permission denied, access '/usr/local/lib/node_modules']
npm ERR!   stack:
npm ERR!    'Error: EACCES: permission denied, access \'/usr/local/lib/node_modules\'',
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'access',
npm ERR!   path: '/usr/local/lib/node_modules' }
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!     /home/kupu/.npm/_logs/2020-05-09T17_52_32_877Z-debug.log

即使我尝试以 sudo 的身份运行它,我也会得到:

kupu@kupu:~/Dropbox/IOT/generic-sensor-demos/sensor-info$ sudo npm install -g polymer-cli
/usr/local/bin/polymer -> /usr/local/lib/node_modules/polymer-cli/bin/polymer.js

> wd@1.11.2 install /usr/local/lib/node_modules/polymer-cli/node_modules/wd
> node scripts/build-browser-scripts

/usr/local/lib/node_modules/polymer-cli/node_modules/mkdirp/index.js:90
                    throw err0;
                    ^

Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/polymer-cli/node_modules/wd/build'
    at Object.mkdirSync (fs.js:753:3)
    at sync (/usr/local/lib/node_modules/polymer-cli/node_modules/mkdirp/index.js:71:13)
    at Object.<anonymous> (/usr/local/lib/node_modules/polymer-cli/node_modules/wd/scripts/build-browser-scripts.js:6:1)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
    at startup (internal/bootstrap/node.js:283:19)
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.9 (node_modules/polymer-cli/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.9: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! wd@1.11.2 install: `node scripts/build-browser-scripts`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the wd@1.11.2 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2020-05-09T17_53_02_303Z-debug.log

那里有可以帮助我的好灵魂吗?

2 个答案:

答案 0 :(得分:1)

您遇到一个典型的npm EACCES权限问题。这与您的用户无权修改npm试图存储全局软件包的目录有关。可能会很烦人。您应该在这里查看哪种解决方案最适合您:https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally

答案 1 :(得分:0)

您可以使用

对其进行修复
node_modules

Unsafe-perm标志设置为true以禁止在运行软件包脚本时切换用户标识符/组标识符。该标志显式设置为false以防止非root用户安装软件包。

您还可以尝试更改sudo chown -R root: <YOUR_USERNAME>/usr/local/lib/node_modules/ sudo chmod -R 775 /usr/local/lib/node_modules/ 的所有权,

要将所有权更改为当前用户作为组-

sudo

绝不要将dataList用于npm相关查询。