Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

yccheok's avatar

Fail to perform npm install during Laravel + ReactJS dockerize setup

Currently, I try to dockerize Laravel + ReactJS stack. First, I try to obtain all Laravel related file and ReactJS related file in my host machine by using the following command.

# Get all Laravel related files.
docker run --rm -v %cd%:/var/www/html -w /var/www/html composer/composer create-project --prefer-dist laravel/laravel /var/www/html/
docker run --rm -v %cd%:/app -w /app composer/composer install
# Get all ReactJS related files.
docker run --rm -v %cd%:/app -w /app php:7.2.8-fpm-alpine3.7 php artisan preset react

I'm able to generate files as in https://github.com/yccheok/snapweb/tree/master/laravel/html

Then, I try to run the following Dockerfile

FROM php:7.2.8-fpm-alpine3.7

COPY . /var/www

WORKDIR /var/www/html

RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

RUN composer install

RUN apk update && \
    apk add postgresql-dev && \
    apk add nodejs && \
    apk add autoconf gcc make libpng-dev

RUN docker-php-ext-install pdo_pgsql

RUN npm install

CMD ["php-fpm", "-F"]

However, I failed at step RUN npm install. The failure messages are

Step 8/9 : RUN npm install
 ---> Running in 4520ad365b3a
npm WARN deprecated [email protected]: Browserslist 2 could fail on reading Browserslist >3.0 config used in other tools.
npm WARN deprecated [email protected]: Browserslist 2 could fail on reading Browserslist >3.0 config used in other tools.
npm WARN deprecated [email protected]: gulp-util is deprecated - replace it, following the guidelines at https://medium.com/gulpjs/gulp-util-ca3b1f9f9ac5
npm WARN notice [SECURITY] tunnel-agent has the following vulnerability: 1 moderate. Go here for more details: https://nodesecurity.io/advisories?search=tunnel-agent&version=0.4.3 - Run `npm i npm@latest -g` to upgrade your npm version, and then `npm audit` to get more info.
npm WARN notice [SECURITY] hoek has the following vulnerability: 1 moderate. Go here for more details: https://nodesecurity.io/advisories?search=hoek&version=2.16.3 - Run `npm i npm@latest -g` to upgrade your npm version, and then `npm audit` to get more info.

> [email protected] install /var/www/html/node_modules/node-sass
> node scripts/install.js

Downloading binary from https://github.com/sass/node-sass/releases/download/v4.9.2/linux_musl-x64-57_binding.node
Download complete
Binary saved to /var/www/html/node_modules/node-sass/vendor/linux_musl-x64-57/binding.node
Caching binary to /root/.npm/node-sass/4.9.2/linux_musl-x64-57_binding.node

> [email protected] postinstall /var/www/html/node_modules/webpack/node_modules/uglifyjs-webpack-plugin
> node lib/post_install.js


> [email protected] postinstall /var/www/html/node_modules/node-sass
> node scripts/build.js

Binary found at /var/www/html/node_modules/node-sass/vendor/linux_musl-x64-57/binding.node
Testing binary
Binary is fine

> [email protected] postinstall /var/www/html/node_modules/gifsicle
> node lib/install.js

  ⚠ spawn /var/www/html/node_modules/gifsicle/vendor/gifsicle ENOENT
  ⚠ gifsicle pre-build test failed
  ℹ compiling from source
  ✖ Error: autoreconf -ivf && ./configure --disable-gifview --disable-gifdiff --prefix="/var/www/html/node_modules/gifsicle/vendor" --bindir="/var/www/html/node_modules/gifsicle/vendor" && make install
Command failed: autoreconf -ivf
autoreconf: Entering directory `.'
autoreconf: configure.ac: not using Gettext
autoreconf: running: aclocal  --output=aclocal.m4t
Can't exec "aclocal": No such file or directory at /usr/share/autoconf/Autom4te/FileUtils.pm line 326.
autoreconf: failed to run aclocal: No such file or directory

    at ChildProcess.exithandler (child_process.js:275:12)
    at emitTwo (events.js:126:13)
    at ChildProcess.emit (events.js:214:7)
    at maybeClose (internal/child_process.js:925:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)

> [email protected] postinstall /var/www/html/node_modules/mozjpeg
> node lib/install.js

  ⚠ spawn /var/www/html/node_modules/mozjpeg/vendor/cjpeg ENOENT
  ⚠ mozjpeg pre-build test failed
  ℹ compiling from source
  ✖ Error: autoreconf -fiv && ./configure --disable-shared --disable-dependency-tracking --with-jpeg8  --prefix="/var/www/html/node_modules/mozjpeg/vendor" --bindir="/var/www/html/node_modules/mozjpeg/vendor" --libdir="/var/www/html/node_modules/mozjpeg/vendor" && make -j2 && make install -j2
Command failed: autoreconf -fiv
autoreconf: Entering directory `.'
autoreconf: configure.ac: not using Gettext
autoreconf: running: aclocal  --output=aclocal.m4t
Can't exec "aclocal": No such file or directory at /usr/share/autoconf/Autom4te/FileUtils.pm line 326.
autoreconf: failed to run aclocal: No such file or directory

    at ChildProcess.exithandler (child_process.js:275:12)
    at emitTwo (events.js:126:13)
    at ChildProcess.emit (events.js:214:7)
    at maybeClose (internal/child_process.js:925:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)

> [email protected] postinstall /var/www/html/node_modules/optipng-bin
> node lib/install.js

  ⚠ spawn /var/www/html/node_modules/optipng-bin/vendor/optipng ENOENT
  ⚠ optipng pre-build test failed
  ℹ compiling from source
  ✖ Error: ./configure --with-system-zlib --prefix="/var/www/html/node_modules/optipng-bin/vendor" --bindir="/var/www/html/node_modules/optipng-bin/vendor" && make install
Command failed: ./configure --with-system-zlib --prefix="/var/www/html/node_modules/optipng-bin/vendor" --bindir="/var/www/html/node_modules/optipng-bin/vendor"

    at ChildProcess.exithandler (child_process.js:275:12)
    at emitTwo (events.js:126:13)
    at ChildProcess.emit (events.js:214:7)
    at maybeClose (internal/child_process.js:925:16)
    at Socket.stream.socket.on (internal/child_process.js:346:11)
    at emitOne (events.js:116:13)
    at Socket.emit (events.js:211:7)
    at Pipe._handle.close [as _onclose] (net.js:554:12)

> [email protected] postinstall /var/www/html/node_modules/pngquant-bin
> node lib/install.js

  ⚠ spawn /var/www/html/node_modules/pngquant-bin/vendor/pngquant ENOENT
  ⚠ pngquant pre-build test failed
  ℹ compiling from source
  ✔ pngquant pre-build test passed successfully
  ✖ Error: pngquant failed to build, make sure that libpng-dev is installed
    at Promise.all.then.arr (/var/www/html/node_modules/pngquant-bin/node_modules/bin-build/node_modules/execa/index.js:231:11)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)
npm WARN [email protected] requires a peer of ajv@^6.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] postinstall: `node lib/install.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] postinstall 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/2018-07-25T08_52_53_382Z-debug.log
ERROR: Service 'laravel' failed to build: The command '/bin/sh -c npm install' returned a non-zero code: 1

Anyone has any idea how to resolve this? To reproduce the problem, you may checkout all files from https://github.com/yccheok/snapweb , then execute docker-compose build

0 likes
0 replies

Please or to participate in this conversation.