TrySound / rollup-plugin-uglify

Rollup plugin to minify generated bundle
MIT License
260 stars 42 forks source link

Cannot Read Property 'end' of undefined #52

Closed ghost closed 6 years ago

ghost commented 6 years ago
import resolve from 'rollup-plugin-node-resolve'
import babel from 'rollup-plugin-babel'
import { uglify } from 'rollup-plugin-uglify'
import commonjs from 'rollup-plugin-commonjs'

export default {
  input: 'src/index.js',
  output: {
    file: 'dist/index.js',
    format: 'umd',
    name: 'Name',
    globals: {
      react: 'React',
    },
  },
  plugins: [
    resolve(),
    babel({
      runtimeHelpers: true,
      exclude: 'node_modules/**',
      plugins: [
        'external-helpers',
      ],
    }),
    commonjs({
      namedExports: {
        'stylis-rule-sheet': ['stylisRuleSheet'],
      },
    }),
    uglify(),
  ],
  external: ['react'],
}

When I run this I get "TypeError: Cannot read property 'end' of undefined"

RikkiGibson commented 6 years ago

I get this error with rollup@0.66.2 and rollup-plugin-uglify@6.0.0.

I get the same error message when using rollup-plugin-terser@3.0.0 instead of rollup-plugin-uglify.

TrySound commented 6 years ago

Could you provide a reproduction example with which code are you trying to minify? Also post the whole stack trace of the error.

RikkiGibson commented 6 years ago

Not in a position to provide a minimal repro just yet, but here's my stack trace:

[!] TypeError: Cannot read property 'end' of undefined
TypeError: Cannot read property 'end' of undefined
    at Object.generateBundle (/Users/rigibson/src/ms-rest-js/node_modules/rollup-plugin-uglify/index.js:38:19)
    at /usr/local/lib/node_modules/rollup/dist/rollup.js:21774:54
    at Array.map (<anonymous>)
    at /usr/local/lib/node_modules/rollup/dist/rollup.js:21773:62
ycjcl868 commented 6 years ago

me too.

gavmck commented 6 years ago

+1

yongtw123 commented 6 years ago

I suspect it's due to environment's rollup version not up to requirement, since event hooks such as renderStart isn't present until rollup version 0.66. To illustrate, I'm currently using gulp-better-rollup, which comes with its own version of rollup, and it's not 0.66 up.

TrySound commented 6 years ago

This is the answer. Look at you terminal with yarn/npm installs. They should warn you about incorrect peer dependencies.

Andersos commented 5 years ago

I was using rullup@0.66.6 and rollup-plugin-terser@3.0.0 and it did not work so I downgraded to older versions.

TrySound commented 5 years ago

@Andersos Could you please provide repo with reproducing of this issue?

Andersos commented 5 years ago

Yes, the repo I had this problem with is this one https://github.com/getas/styleguide

Edit: In the root of the repo you can update to rullup@0.66.6 and rollup-plugin-terser@3.0.0 and then you can go into /components/movie-card and then run yarn. It will run the root rollup.config.js.

TrySound commented 5 years ago

@Andersos You are probably trying to build with global rollup version. Package in those directory doesn't know about local rollup. Try to change the commend with this

"build": "../../node_modules/.bin/rollup src/index.js --config ../../rollup.config.js -o dist/index.js"
Andersos commented 5 years ago

You were right. I had rollup@0.64.1 installed globaly. Hope others that come over this thread also checks that.

You can list out global dependencies with either npm list -g --depth=0 or yarn global list.

I uninstalled rollup with npm uninstall -g rollup.

RikkiGibson commented 5 years ago

It’s very likely this was my problem too :)

I guess this is an argument for npx over npm i -g.