Next.js: Build errors

Created on 31 Mar 2017  路  7Comments  路  Source: vercel/next.js

{ Error: commons.js from UglifyJs
Name expected [commons.js:49631,6]
    at /Users/tknipfer/Desktop/plate/node_modules/next/dist/server/build/index.js:181:21
    at /Users/tknipfer/Desktop/plate/node_modules/webpack/lib/Compiler.js:267:15
    at Compiler.emitRecords (/Users/tknipfer/Desktop/plate/node_modules/webpack/lib/Compiler.js:362:37)
    at /Users/tknipfer/Desktop/plate/node_modules/webpack/lib/Compiler.js:260:12
    at /Users/tknipfer/Desktop/plate/node_modules/webpack/lib/Compiler.js:355:11
    at next (/Users/tknipfer/Desktop/plate/node_modules/tapable/lib/Tapable.js:154:11)
    at Compiler.compiler.plugin (/Users/tknipfer/Desktop/plate/node_modules/webpack/lib/performance/SizeLimitsPlugin.js:99:4)
    at Compiler.applyPluginsAsyncSeries1 (/Users/tknipfer/Desktop/plate/node_modules/tapable/lib/Tapable.js:158:13)
    at Compiler.afterEmit (/Users/tknipfer/Desktop/plate/node_modules/webpack/lib/Compiler.js:352:8)
    at Compiler.<anonymous> (/Users/tknipfer/Desktop/plate/node_modules/webpack/lib/Compiler.js:347:14)
  errors: [ 'commons.js from UglifyJs\nName expected [commons.js:49631,6]' ],
  warnings: [] }

When I try to deploy using now or build I get this error?
Running on the latest version of next using a custom express server.
Everything works fine when running in dev mode.

Here is the repo: https://github.com/knipferrc/plate/tree/next

Most helpful comment

Not sure what could be causing this, but if you'd like to disable uglifying, a next.config.js like this will do the trick:

module.exports = {
  webpack(cfg) {
    cfg.plugins = cfg.plugins.filter(plugin => {
      if (plugin.constructor.name === 'UglifyJsPlugin') {
        return false;
      } else {
        return true;
      }
    });

    return cfg;
  }
};

All 7 comments

I got the same error as well :\

Not sure what could be causing this, but if you'd like to disable uglifying, a next.config.js like this will do the trick:

module.exports = {
  webpack(cfg) {
    cfg.plugins = cfg.plugins.filter(plugin => {
      if (plugin.constructor.name === 'UglifyJsPlugin') {
        return false;
      } else {
        return true;
      }
    });

    return cfg;
  }
};

From one quick google search, the possibility is that Uglify can't understand some ES6 syntax, thus the error.

Reference:
https://github.com/terinjokes/gulp-uglify/issues/66

I'm getting a similar error. I realize the problem is I have some non-es5 code hitting UglifyJS, and it's probably a rogue ES6 node module.

@rauchg Is there an expected way we can find the source of these uglify errors? The error contains a line of code and column in commons.js, but commons.js is never written to file.

If I disable uglify, the build finishes and writes a combined version of commons.js and a few other files, making it so I can't find the line number.

Right now it seems there's no way to get to the line/column in commons.js where my error is occuring, making it very difficult to find where in my code the problem lies.

EDIT: I got a copy of the pre-minified commons.js by disabled uglify, then going into my node_modules/next/dist/server/build/webpack.js and changing the combineAssetsPlugin to only combine commons.js with itself. Now I have a line number.

It would be great if Next made this easier. I would submit a PR, but I know almost nothing of advanced webpack.

@ajoslin actually this is something pretty hard to do with the current case of uglifyjs.
We are tracking this issue with https://github.com/zeit/next.js/issues/1195

I also had to fix this issue several times. Only solution is comment out code and find which gives the error.

I'm actually getting this even when the babel config should be transpiling to a target Uglify should understand. let is still showing for code for things in the /pages directory. I'm using an express server, and all the server code is properly being transpiled.

.babelrc

{
  "presets": ["env", "stage-2"]
}

I'll try to make a minimal POC later.

I'm experiencing the same problem with universal-url, which references whatwg-url which ships with ES6 syntax.

Want to mention, for benefit of others reading this, that you can run npm build and find commons.js in the build's .next folder. Though it doesn't tell you the file, it points you to the offending source, so it might provide a clue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

olifante picture olifante  路  3Comments

irrigator picture irrigator  路  3Comments

timneutkens picture timneutkens  路  3Comments

YarivGilad picture YarivGilad  路  3Comments

wagerfield picture wagerfield  路  3Comments