question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Failed to minify format.js

See original GitHub issue

I am working on a React.js project and trying to use Winston@3.0.0 within this project. I followed the comments outlined here:

When I go to run our build using webpack, I see the following error:

Starting type checking and linting service...
Using 1 worker with 2048MB memory limit
ts-loader: Using typescript@2.7.1 and D:\dev\my-project\our-ui\tsconfig.json
Failed to compile.

Failed to minify the code from this file:

        ./node_modules/logform/format.js:7

Read more here: http://bit.ly/2tRViJ9

npm ERR! code ELIFECYCLE
npm ERR! errno 1

At first I tried changing the custom error object from ES6 classes to the old fashioned way:

function InvalidFormatError(formatFn) {
  var instance = new Error(`Format functions must be synchronous taking a two arguments: (info, opts)
Found: ${formatFn.toString().split('\n')[0]}\n`);
  Object.setPrototypeOf(instance, Object.getPrototypeOf(this));
  if (Error.captureStackTrace) {
    Error.captureStackTrace(instance, InvalidFormatError);
  }
  return instance;
}

InvalidFormatError.prototype = Object.create(Error.prototype, {
  constructor: {
    value: Error,
    enumerable: false,
    writable: true,
    configurable: true
  }
});

if (Object.setPrototypeOf){
  Object.setPrototypeOf(InvalidFormatError, Error);
} else {
  InvalidFormatError.__proto__ = Error;
}

But that still produced the same errror:

Starting type checking and linting service...
Using 1 worker with 2048MB memory limit
ts-loader: Using typescript@2.7.1 and D:\dev\my-project\our-ui\tsconfig.json
Failed to compile.

Failed to minify the code from this file:

        ./node_modules/logform/format.js:7

Read more here: http://bit.ly/2tRViJ9

npm ERR! code ELIFECYCLE
npm ERR! errno 1

Any help is appreciated, not sure if this is a logform issue our a webpack config issue.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
DABHcommented, Jul 23, 2018

Hi @mfrisbey , thanks for the thorough comment and your work on this!

Indeed, the File transport doesn’t work in the browser for the reasons you mentioned. Others like Console, various HTTP-based transports (post your logs to a server), etc. should work.

I think this change is essentially a requirement to achieve first-class browser support for winston, which is a (the main?) goal for 3.1. Browsers need ES5 for the foreseeable future.

I’d like @indexzero to +1 this before merging since it is a significant change, but I’m confident enough to say that you should open the PRs for these on all 3 repos. If we don’t hear anything from @indexzero then I will probably merge these, but ideally we’ll get consensus from at least one other maintainer 😃 Thanks again for taking the initiative on this, it’s appreciated!

1reaction
mfrisbeycommented, Jul 23, 2018

@DABH @ChrisAlderson @indexzero I recently had to precompile a module I was working on, so I spent a little time and configured this module to precompile as well. You can see the result at https://github.com/mfrisbey/logform/tree/publish-precompiled. I’d be happy to contribute these changes as a pull request, but since it’s fairly invasive I thought I’d run it by you first. All the tests are passing.

I had to make similar changes to winston and winston-transport, so those changes would also need to be contributed in order for winston to work in a browser setting (in my case, a React app).

NOTE For those wanting to consume winston from a browser, the File transport won’t work. For security reasons, fs functionality is unavailable in the context of a browser. I verified that Console works but I haven’t tried any of the others.

What do these modifications do? On publish, precompiles all javascript files into a build directory, which is included in the final package. Non-compiled javascript source is excluded from the package.

What Changed?

  • Introduced dev dependencies to:
    • Babel (does the work of precompiling)
    • Rimraf (removes the build directory on precompile)
  • Changed the package’s main file to build/index.js
  • Moved all javascript files from root directory to a src folder
  • Updated tests to reference files in src folder instead of root

What will it break? Since the source files were moved to a different directory, any requires to paths in the module will break (i.e. require('logform/json');). I changed one such occurrence in the winston module, so that pull request would also need to be merged before moving forward.

Feel free to reach out to me if you have questions or would like to discuss anything further. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Failed to minify the code from this file #1529 - GitHub
Failed to compile. Failed to minify the code from this file: ./node_modules/react-intl/lib/utils.js:29 Environment yarn version 1.16.0 no...
Read more >
Failed to minify the code from this file - Stack Overflow
npm run build fails to minify Before react-scripts@2.0.0 , this problem was caused by third party node_modules using modern JavaScript ...
Read more >
Minify javascript broke website formatting – bug report
If you re-enable Minify, and go to Performance>Minify and disable the JS minify, save all settings, and purge the cache, you will see...
Read more >
JS Beautify and Minify - Online
Beautify (prettify) your JS data or minify (uglify) it with advanced formatting options. Our site has an easy to use online tool to...
Read more >
TerserWebpackPlugin | webpack
This plugin uses terser to minify/minimize your JavaScript. Getting Started. Webpack v5 comes with the latest terser-webpack-plugin out of the box. If you...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found