MacOS:如何安装带有或不带有Chromium的puppeteer?

时间:2019-02-27 14:15:13

标签: macos npm chromium puppeteer

我正在尝试在macOS(Mojave)10.14.3上全局安装puppeteer

  1. 首次失败(在sudo su模式下):npm install -g puppeteer
> puppeteer@1.12.2 install /usr/local/lib/node_modules/puppeteer
> node install.js

ERROR: Failed to download Chromium r624492! Set "PUPPETEER_SKIP_CHROMIUM_DOWNLOAD" env variable to skip download.
{ Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/puppeteer/.local-chromium'
  -- ASYNC --
    at BrowserFetcher.<anonymous> (/usr/local/lib/node_modules/puppeteer/lib/helper.js:108:27)
    at Object.<anonymous> (/usr/local/lib/node_modules/puppeteer/install.js:64:16)
    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)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:743:3)
  errno: -13,
  code: 'EACCES',
  syscall: 'mkdir',
  path: '/usr/local/lib/node_modules/puppeteer/.local-chromium' }
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! puppeteer@1.12.2 install: `node install.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the puppeteer@1.12.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!     /var/root/.npm/_logs/2019-02-27T14_04_04_609Z-debug.log
  1. 第二次失败:我成功地从https://commondatastorage.googleapis.com/chromium-browser-snapshots/index.html?prefix=Mac/635943/手动安装了Chromium,然后(在sudo su模式下):

npm get | grep PUPPETEER

PUPPETEER_EXECUTABLE_PATH = "/Applications/Chromium.app/Contents/MacOS/Chromium"
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD = true
PUPPETEER_EXECUTABLE_PATH = "/Applications/Chromium.app/Contents/MacOS/Chromium"
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD = true

npm install -g puppeteer

> puppeteer@1.12.2 install /usr/local/lib/node_modules/puppeteer
> node install.js

ERROR: Failed to download Chromium r624492! Set "PUPPETEER_SKIP_CHROMIUM_DOWNLOAD" env variable to skip download.
{ Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/puppeteer/.local-chromium'
  -- ASYNC --
    at BrowserFetcher.<anonymous> (/usr/local/lib/node_modules/puppeteer/lib/helper.js:108:27)
    at Object.<anonymous> (/usr/local/lib/node_modules/puppeteer/install.js:64:16)
    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)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:743:3)
  errno: -13,
  code: 'EACCES',
  syscall: 'mkdir',
  path: '/usr/local/lib/node_modules/puppeteer/.local-chromium' }
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! puppeteer@1.12.2 install: `node install.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the puppeteer@1.12.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!     /var/root/.npm/_logs/2019-02-27T14_07_19_001Z-debug.log

我在这里做什么错了?

2 个答案:

答案 0 :(得分:0)

您尝试吗?

npm config set user 0
npm config set unsafe-perm true
npm install -g puppeteer

答案 1 :(得分:0)

几天前这对我来说还算不错,但并没有出现完全相同的错误