cachethq / cachethq/Docker

Re-building Cachet in Docker with npm fails due to uglify-js

Open
#394 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Shell
Stars
439
Forks
271
PR merge metrics
No merged PRs in 30d

Description

I have a Dockerfile like the following in order to re-build the application in `2.4` and apply some CSS changes
```
>cat Dockerfile
# build stage
FROM cachethq/docker:latest
COPY public/img/login-logo.png /var/www/html/public/img/login-logo.png
COPY resources /var/www/html/resources
USER root
RUN apk add --no-cache npm
USER 1001
RUN mkdir -p /home/www-data/.npm/ && cd /var/www/html && npm install && npm run production

# docker stage
FROM cachethq/docker:latest
RUN rm -fr /var/www/html
COPY --from=0 --chown=1001 /var/www/html /var/www/html
COPY entrypoint.sh /sbin/entrypoint.sh
USER root
RUN apk add --no-cache vim
USER 1001
```

Lately I have noticed that `uglify-js` is giving this error.
```
DONE Compiled successfully in 30631ms 11:59:51 AM

Whoops! We had trouble minifying "public/dist/js/all.js". Perhaps you need to use mix.babel() instead?

/var/www/html/node_modules/laravel-mix/src/webpackPlugins/CustomTasksPlugin.js:64
throw e;
^
SyntaxError: Name expected
at JS_Parse_Error.get (eval at (/var/www/html/node_modules/uglify-js/tools/node.js:27:1), :86:23)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! cachet@ production: `cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the cachet@ production 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! /home/www-data/.npm/_logs/2020-12-22T11_59_51_992Z-debug.log
```

When I build the image using an older docker image from a previous build from my docker registry, that has `node_modules` already installed, then the build succeeds.
I have verified that the `uglify-js` is in the same version in both images.
```
bash-5.0$ npm list uglify-js
cachet@ /var/www/html
`-- laravel-mix@2.1.14
+-- html-loader@0.4.5
| `-- html-minifier@3.5.21
| `-- uglify-js@3.4.10
+-- uglify-js@2.8.29
`-- webpack@3.12.0
`-- uglifyjs-webpack-plugin@0.4.6
`-- uglify-js@2.8.29 deduped
```

However, if I diff the two folders (the one created in a new npm install, and the one that was installed in an older image) the actual files differ. So, as a workaround, after `npm install` I am replacing the `node_modules/uglify-js` from an older image to the `node_modules` and the `npm run production` works without any issues and this was my workaround to the problem.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.