Search code examples
node.jsherokuecmascript-5webhose

ES5: 'use strict' within dependency fails to be minified by Heroku


I am trying to deploy on Heroku, where I'm given the following error: remote: Failed to minify the code from this file: remote: ./node_modules/webhoseio/webhoseio.js:13

Upon inspecting this dependency, I found that it uses the ES5 'use strict'; declaration. How can I have Heroku compile this dependency?

EDIT: Package.json file { "name": "stocks-app", "version": "1.0.0", "description": "Mern Demo", "main": "server.js", "scripts": { "start": "if-env NODE_ENV=production && npm run start:prod || npm run start:dev", "start:prod": "babel-node server.js", "start:dev": "concurrently \"nodemon --ignore 'client/*'\" \"npm run client\"", "client": "cd client && npm run start", "install": "cd client && yarn install", "build": "cd client && npm run build", "heroku-postbuild": "npm run build" }, "author": "", "license": "ISC", "devDependencies": { "babel": "^6.23.0", "babel-cli": "^6.26.0", "babel-preset-env": "^1.7.0", "concurrently": "^4.1.0", "nodemon": "^1.18.9" }, "dependencies": { "alphavantage": "^1.2.0", "axios": "^0.18.0", "brain.js": "^1.6.0", "cors": "^2.8.5", "dotenv": "^6.2.0", "express": "^4.16.3", "if-env": "^1.0.4", "mdbreact": "^4.8.5-patch.1", "mongoose": "^5.4.0", "newsapi": "^2.4.0", "request": "^2.88.0", "webhoseio": "^1.0.2" } }


Solution

  • I resolved this by turning off minification in my Webpack config. Instead of using the CRA-preconfigured Webpack ES-Lint loader, I installed the HTML-Loader and set loader to that. Following, I set minimize to false. Here's how:

    module: {
    rules: [
      {
        use: [
          {
            options: {
              formatter: eslintFormatter,
              eslintPath: require.resolve('eslint'),
              minimize: false,
            },
            loader: require.resolve('html-loader'),
          },
        ],}}