尝试为条带安装netlify-lambda时,npm写访问被拒绝

时间:2019-02-05 16:20:31

标签: npm

当我试图在gatsby应用程序中安装netlify-lambda时会发生这种情况

npm install -g netlify-lambda
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules/netlify-lambda/node_modules/@babel/plugin-proposal-object-rest-spread
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules/netlify-lambda/node_modules/@babel/parser
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules/netlify-lambda/node_modules/@babel/helper-create-class-features-plugin
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules/netlify-lambda/node_modules/@babel/types
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules/netlify-lambda/node_modules/@babel/generator
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules/netlify-lambda/node_modules/caniuse-lite
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules/netlify-lambda/node_modules/duplexify/node_modules/readable-stream
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules/netlify-lambda/node_modules/duplexify
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules/netlify-lambda/node_modules/webpack
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules/netlify-lambda/node_modules/@babel
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules/netlify-lambda/node_modules
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules/netlify-lambda/node_modules/duplexify/node_modules
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules
npm ERR! path /usr/local/lib/node_modules/netlify-lambda/node_modules/@babel/plugin-proposal-object-rest-spread
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access
npm ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules/netlify-lambda/node_modules/@babel/plugin-proposal-object-rest-spread'
npm ERR!  { [Error: EACCES: permission denied, access '/usr/local/lib/node_modules/netlify-lambda/node_modules/@babel/plugin-proposal-object-rest-spread']
npm ERR!   stack:
npm ERR!    'Error: EACCES: permission denied, access \'/usr/local/lib/node_modules/netlify-lambda/node_modules/@babel/plugin-proposal-object-rest-spread\'',
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'access',
npm ERR!   path:
npm ERR!    '/usr/local/lib/node_modules/netlify-lambda/node_modules/@babel/plugin-proposal-object-rest-spread' }
npm ERR!

尝试但不起作用:

sudo chown -R $ USER:$ GROUP〜/ .npm 须藤chown -R $ USER:$ GROUP〜/ .config

sudo npm install -g netlify-lambda

重新安装npm

1 个答案:

答案 0 :(得分:0)

您在Netlify构建容器中没有root用户访问权限,因此sudo对您没有任何帮助。

您也不需要手动npm install这样的操作-您应该将package.json放在仓库的根目录中,并且应该为软件包设置规格。然后,Netlify自动运​​行npm install(有关更多详细信息,请参见this article),安装所需的文件并将其放在$ PATH中,以便您可以运行安装过程中生成的任何二进制文件。

本文介绍了我们的连续部署环境的流程:https://www.netlify.com/blog/2016/10/18/how-our-build-bots-build-sites/

TL; DR您应该可以有效地将netlify-lambda作为依赖项放入package.json中,然后在构建期间运行它,而无需进一步安装。