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.

ES2015 import fails with Rollup, no docs

See original GitHub issue

I’m using Winston in an ES2015 project. I import Winston with import log from 'winston' and log with log.info(), log.debug(), etc. When I transpile and run with Babel it works just fine.

However if I use Rollup to resolve all the relative import paths and then the babel Rollup plugin to transpile (with the es2015-rollup plugin for Babel), the import of Winston fails. In particular, it imports the following object:

{ transports: 
   { console: 
      EventEmitter {
        domain: null,
        _events: {},
        _eventsCount: 0,
        _maxListeners: undefined,
        silent: false,
        raw: false,
        name: 'console',
        formatter: undefined,
        level: undefined,
        handleExceptions: false,
        exceptionsLevel: 'error',
        humanReadableUnhandledException: false,
        json: false,
        colorize: false,
        prettyPrint: false,
        timestamp: false,
        showLevel: true,
        label: null,
        logstash: false,
        depth: null,
        align: false,
        stderrLevels: [Object],
        eol: '\n',
        _onError: [Function: bound ] } },
  exceptionHandlers: {} }

This can be fixed by using import * as log from 'winston', but this is not at all obvious. I’m not sure what Rollup is doing in detail, but it looks like a great piece of ES2015 tooling, so Winston should work with it cleanly.

I would recommend adding a section to the Winston README on how to use it with ES2015, and perhaps add a caveat with respect to Rollup. Currently there is no guidance, and nothing on Google either.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:2
  • Comments:11 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
paulericksoncommented, Jan 25, 2019

Definitely still broken in 3.1.0.

If you use Node’s builtin ‘stream’ module instead of ‘readable-stream’ from NPM, you resolve the undefined / circular dependency thing, and if you get rid of the dynamic import crap in logform, then it works for me.

To put that in the hackiest possible terms…

find node_modules/{winston,winston-transport,logform} -type f -exec sed -i -e "s/require(.readable-stream.)/require('stream')/g" -e "s/require(.readable-stream\/writable.)/require('stream').Writable/g" -e "s/exposeFormat('\(\w*\)', '\(.*\)'/format.\1 = require('.\/\2.js'/g" -e "s/exposeFormat('\(\w*\)'/format.\1 = require('.\/\1.js'/g" {} +
1reaction
ipol2ncommented, Jun 12, 2018

This issue has been solved in 3.0.0

Read more comments on GitHub >

github_iconTop Results From Across the Web

@rollup/plugin-typescript - npm
Create a rollup.config.js configuration file and import the plugin: ... This can fix plugin errors when parsing files outside the current ...
Read more >
Why is Rollup trying to parse my dependency's TypeScript as ...
I'm suspecting that Rollup successfully compiles the child module to an ESNext module that includes the line import parent from 'parent' , and ......
Read more >
Build Options - Vite
If the build is configured to use a non-HTML custom entry via build.rollupOptions.input , then it is necessary to manually import the polyfill...
Read more >
Introduction - rollup.js
This allows you to build on top of existing tools and modules without adding extra ... if that fails, it will then try...
Read more >
rollup.js
This will not throw an error if one of the entry point files is not available. ... in the ES2015 specification, since a...
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