尝试在Docker容器中安装puppeteer时出错

时间:2020-05-21 18:19:04

标签: node.js ruby linux docker npm

我有一个专门用于Ruby on Rails的docker容器,它基本上是从Ruby docker容器构建的。在运行捆绑安装并成功完成所有其他操作之后,它随后尝试运行npm install并尝试安装puppeteer。这是我在下面收到的错误:

sudo docker exec -ti app_1 npm install

> puppeteer@3.1.0 install /myapp/node_modules/puppeteer
> node install.js

/myapp/node_modules/puppeteer/install.js:175
            } catch {
                    ^

SyntaxError: Unexpected token {
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:599:28)
    at Object.Module._extensions..js (module.js:646:10)
    at Module.load (module.js:554:32)
    at tryModuleLoad (module.js:497:12)
    at Function.Module._load (module.js:489:3)
    at Function.Module.runMain (module.js:676:10)
    at startup (bootstrap_node.js:187:16)
    at bootstrap_node.js:608:3
npm WARN ws@7.3.0 requires a peer of bufferutil@^4.0.1 but none is installed. You must install peer dependencies yourself.
npm WARN ws@7.3.0 requires a peer of utf-8-validate@^5.0.2 but none is installed. You must install peer dependencies yourself.

npm ERR! code ELIFECYCLE
npm ERR! errno 1                                                                                                                                                                                                                                              npm ERR! puppeteer@3.1.0 install: `node install.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the puppeteer@3.1.0 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-21T18_12_14_082Z-debug.log

如果我查看输出底部打印的日志文件,这是我在最底部看到的内容:

1284 info lifecycle ws@7.3.0~install: ws@7.3.0
1285 silly install yauzl@2.10.0
1286 info lifecycle yauzl@2.10.0~install: yauzl@2.10.0
1287 silly install extract-zip@2.0.0
1288 info lifecycle extract-zip@2.0.0~install: extract-zip@2.0.0
1289 silly install puppeteer@3.1.0
1290 info lifecycle puppeteer@3.1.0~install: puppeteer@3.1.0
1291 verbose lifecycle puppeteer@3.1.0~install: unsafe-perm in lifecycle false
1292 verbose lifecycle puppeteer@3.1.0~install: PATH: /usr/lib/node_modules/npm/bin/node-gyp-bin:/myapp/node_modules/puppeteer/node_modules/.bin:/myapp/node_modules/.bin:/usr/local/bundle/bin:/usr/local/bundle/gems/bin:/usr/local/sbin:/usr/local/bin:/usr
/sbin:/usr/bin:/sbin:/bin
1293 verbose lifecycle puppeteer@3.1.0~install: CWD: /myapp/node_modules/puppeteer
1294 silly lifecycle puppeteer@3.1.0~install: Args: [ '-c', 'node install.js' ]
1295 silly lifecycle puppeteer@3.1.0~install: Returned: code: 1  signal: null
1296 info lifecycle puppeteer@3.1.0~install: Failed to exec install script
1297 verbose unlock done using /root/.npm/_locks/staging-bcb8ce459d19ee76.lock for /myapp/node_modules/.staging
1298 warn ws@7.3.0 requires a peer of bufferutil@^4.0.1 but none is installed. You must install peer dependencies yourself.
1299 warn ws@7.3.0 requires a peer of utf-8-validate@^5.0.2 but none is installed. You must install peer dependencies yourself.
1300 verbose stack Error: puppeteer@3.1.0 install: `node install.js`
1300 verbose stack Exit status 1
1300 verbose stack     at EventEmitter.<anonymous> (/usr/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:280:16)
1300 verbose stack     at emitTwo (events.js:126:13)
1300 verbose stack     at EventEmitter.emit (events.js:214:7)
1300 verbose stack     at ChildProcess.<anonymous> (/usr/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)                                                                                                                                  1300 verbose stack     at emitTwo (events.js:126:13)
1300 verbose stack     at ChildProcess.emit (events.js:214:7)
1300 verbose stack     at maybeClose (internal/child_process.js:925:16)
1300 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)
1301 verbose pkgid puppeteer@3.1.0
1302 verbose cwd /myapp
1303 verbose Linux 5.4.0-31-generic
1304 verbose argv "/usr/bin/node" "/usr/bin/npm" "install"
1305 verbose node v8.9.3
1306 verbose npm  v5.5.1
1307 error code ELIFECYCLE
1308 error errno 1
1309 error puppeteer@3.1.0 install: `node install.js`
1309 error Exit status 1
1310 error Failed at the puppeteer@3.1.0 install script.
1310 error This is probably not a problem with npm. There is likely additional logging output above.
1311 verbose exit [ 1, true ]

根据this GitHub issue,建议只运行npm install puppeteer --unsafe-perm=true。但是,当我执行该操作时,会收到相同的确切错误。

仍在学习Docker,因此我不确定是否需要在构建过程中将其他文件包含到Dockerfile中。这是我的Dockerfile的样子:

FROM ruby:2.5.1-alpine
ENV BUNDLER_VERSION=2.0.2

RUN apk add --update --no-cache \
        binutils-gold \
        build-base \
        curl \
        file \
        g++ \
        gcc \
        git \
        less \
        libstdc++ \
        libffi-dev \
        libc-dev \
        linux-headers \
        libxml2-dev \
        libxslt-dev \
        libgcrypt-dev \
        make \
        netcat-openbsd \
        nodejs \
        openssl \
        pkgconfig \
        postgresql-dev \
        python \
        tzdata \
        yarn

RUN gem install bundler -v 2.0.2
RUN mkdir /myapp
WORKDIR /myapp
COPY Gemfile /myapp/Gemfile
COPY Gemfile.lock /myapp/Gemfile.lock
RUN bundle config build.nokogiri --use-system-libraries
RUN bundle check || bundle install

COPY . /myapp
COPY entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh
ENTRYPOINT ["entrypoint.sh"]
EXPOSE 3000

CMD ["rails", "server", "-b", "0.0.0.0"]%

我注意到有关bufferutilutf-8-validate对等体的两个警告,因此我成功安装了它们,但仍然遇到相同的错误

任何解决此npm install puppeteer问题的建议将不胜感激。

2 个答案:

答案 0 :(得分:2)

将node和npm更新到这些版本对我来说解决了这个问题:

$ node -v
v12.17.0
$ npm -v
6.14.4

答案 1 :(得分:1)

当我们输入npm install puppeteer时,它将安装最新版本3.1.0。最新版本似乎有问题。

1248 verbose node v8.9.3
1249 verbose npm  v5.5.1
1250 error code ELIFECYCLE
1251 error errno 1
1252 error puppeteer@3.1.0 install: `node install.js`
1252 error Exit status 1
1253 error Failed at the puppeteer@3.1.0 install script.
1253 error This is probably not a problem with npm. There is likely additional logging output above.
1254 verbose exit [ 1, true ]

我尝试使用版本3.0.0,它可以正常工作。因此,如果可以的话,可以使用版本3.0.0作为解决方法。

/ # npm i puppeteer@3.0.0

> puppeteer@3.0.0 install /node_modules/puppeteer
> node install.js

(node:145) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): The "original" argument must be of type function
(node:145) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
npm WARN saveError ENOENT: no such file or directory, open '/package.json'
npm WARN enoent ENOENT: no such file or directory, open '/package.json'
npm WARN !invalid#1 No description
npm WARN !invalid#1 No repository field.
npm WARN !invalid#1 No README data
npm WARN !invalid#1 No license field.

+ puppeteer@3.0.0
added 49 packages in 3.046s