簡體   English   中英

嘗試在 Docker 容器中安裝 puppeteer 時出錯

[英]Error when trying to install puppeteer in Docker container

我有一個 docker 容器,專門用於 Rails 上的 Ruby,它基本上是由 Ruby Z05B6053C41A2130AFD68B4DAE 容器構建的。 在它成功運行 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

如果我查看打印在 output 底部的日志文件,這就是我在最底部看到的內容:

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 ]

根據這個 GitHub 問題,建議只是簡單地運行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問題的建議將不勝感激。

將節點和 npm 更新到這些版本解決了我的問題:

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

當我們輸入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版本的 go 作為解決方法,如果您對此感到滿意的話。

/ # 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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM