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.

Super expression is undefined when using rollup

See original GitHub issue

When used with rollup it throws an error at runtime:

Uncaught TypeError: Super expression must either be null or a function, not undefined
    at _inherits (root.js:25)
    at root.js:38
    at root.js:161
    at createCommonjsModule (index.js:3)
    at processor.js:254

With webpack works fine. And the app works fine until I add styled-components. I wasn’t sure if issue it here since it can be a problem with rollup-plugin-commonjs or even react… I left a reproduction repo here: NicolasParada/styled-components

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:13 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
mxstbrcommented, Oct 15, 2016

Thanks to the amazing @Rich-Harris, we’re now bundling with Rollup which not only means a reduction of size for the UMD bundle, but also a .es.js bundle that will fix this issue!

1reaction
Rich-Harriscommented, Oct 15, 2016

Okay, I’ve done some digging. It looks like this is one of this incredibly frustrating interop headaches caused by back-and-forth conversion between CommonJS and ES modules. Specifically, it looks like the add-module-exports Babel plugin is causing havoc, because it violates the expectation in rollup-plugin-commonjs that a module with __esModule: true will have exports.default rather than module.exports.

The good news is that it’s easy to fix – just use the dist file rather than bundling the library yourself:

import styled from 'styled-components/dist/styled-components.js'

Or, use the existing import but update your Rollup config:

import { resolve } from 'path'
const styledComponentsDist = resolve(__dirname, 'node_modules/styled-components/dist/styled-components.js')

export default {
  entry: 'src/main.js',
  dest: 'dist/bundle.js',
  preferConst: true,
  plugins: [
    {
      resolveId (importee) {
        if (importee === 'styled-components') return styledComponentsDist;
      }
    },
    replace({
      'process.env.NODE_ENV': JSON.stringify('development')
    }),
    ...

Slightly off-topic, but as part of my digging I experimented with building this library with Rollup rather than Webpack (so that it could export an ES module bundle for the benefit of people using Webpack 2 or Rollup like @NicolasParada). The UMD build is 13% smaller (20,549 bytes gzipped down from 23,553) and parses roughly 60% quicker (~8ms in Chrome down from ~20ms, similar increase in Safari, less in Firefox). Any interest in a PR? Totally cool if not but the offer’s there 😀

Read more comments on GitHub >

github_iconTop Results From Across the Web

Flow rollup, react and babel TypeError: Super expression ...
I'm trying to use flow , babel and rollup , but my code breaks when adding flow. I have tried the rollup-plugin-flow and...
Read more >
[Solved]-Flow rollup, react and babel TypeError - appsloveworld
Coding example for the question Flow rollup, react and babel TypeError: Super expression must either be null or a function, not undefined-babel.js.
Read more >
Babelhelpers.Js Throws Super Expression Must Either Be Null ...
alejandronanez you can remove externalhelpers from your.babelrc file and enable it back only on your rollup.config.js using the ...
Read more >
Javascript – Uncaught TypeError: this.method is not a function ...
electronjavascriptnode.jsrollup ... It should be said that app.js is the electron.js renderer process and it bundled using rollup.js.
Read more >
GROUP BY - MariaDB Knowledge Base
As with the select expression, if you reference non-grouped columns in the HAVING clause, the behavior is undefined. By default, if a GROUP...
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