【问题标题】:Error when trying to install puppeteer in Docker container尝试在 Docker 容器中安装 puppeteer 时出错
【发布时间】:2020-05-29 00:35:52
【问题描述】:

我有一个专门用于 Ruby on Rails 的 docker 容器,它基本上是从 Ruby docker 容器构建的。在它成功运行 bundle install 和其他所有内容后,它会尝试运行 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 问题的建议将不胜感激。

【问题讨论】:

    标签: node.js ruby linux docker npm


    【解决方案1】:

    将 node 和 npm 更新到这些版本解决了我的问题:

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

    【讨论】:

    • 帮我解决了这个问题,谢谢。将 dockerfile 更改为“FROM node:12”,而不是之前的旧 v8。
    【解决方案2】:

    当我们输入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
    

    【讨论】:

    • Puppeteer 现在在 v5.3.1 上,并且从他们的自述文件开始,“从 v3.0.0 开始 Puppeteer 开始依赖 Node 10.18.1+”确保 docker 容器基于足够高的 Node 版本
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-08-06
    • 1970-01-01
    • 2017-01-15
    • 1970-01-01
    • 2021-01-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多