0

I use React.js, Webpack, ...props syntax, arrow functions.

When I run "npm run build", I get this error:

ERROR in bundle.js from UglifyJs SyntaxError: Unexpected token punc «(», expected punc «:» [bundle.js:77854,15]

Here is my debug.log

enter image description here

My webpack.config

enter image description here

How to run build successfully?


I found the line which causes the bug, here it is:

import { BootstrapTable, TableHeaderColumn } from 'react-bootstrap-table';

I don't know why. :(

Without it, all my ES6 syntax works and compiled without any errors.

Any Help please

4
  • If you're trying to compress the bundle output file with UglifyJS2 it might be that it doesn't support ES6... Commented Mar 5, 2017 at 12:21
  • You could compress it manually with jscompress.com though (it looks like this compressor is using an ES6 compressor individually; check the ECMAScript 2016 (experimental) option) Commented Mar 5, 2017 at 12:23
  • Also, are you minifying the bundle with babel ? I never used it :v, but it probably supports ES6 and there are some related questions Commented Mar 5, 2017 at 12:26
  • I'm a newbie of Webpack. I don't really understand this. I followed a tutorial, did some react and now I try to build but doesnt work. BUT the --watch command to compile DEV bundle work great. Commented Mar 5, 2017 at 12:32

3 Answers 3

1

This error happens if you use have an npm dependency that has ES6 syntax. It happended to me, too, with Preact (see https://github.com/developit/preact-compat/issues/155).

You can fix it by adding the dependency explicitly to the modules that are loaded through babel, like so:

module: {
    rules: [
        {
            test: /\.js$/,
            loader: 'babel-loader',
            include: [
                srcPath,
                // we need to include preact-compat
                // otherwise uglify will fail
                // @see https://github.com/developit/preact-compat/issues/155
                path.resolve(__dirname, '../../../node_modules/preact-compat/src')
            ]
        }
    ]
}
Sign up to request clarification or add additional context in comments.

5 Comments

Oh! Yeah, okay! It looks good but In my case what is the dependency which needs to be add in the include ?
@Steffi babel-loader
no, babel-loader is not included in the bundle. Look in the package.json files of your dependencies, if they have a property "jsnext:main", you need to explicitly run them through babel for Uglify to work
@handoncloud I'm not blind, the babel-loader is in the webpack config, but it is not included in the bundle. I'm talking about configuring the babel-loader explicitly to include a package from node_modules that has the jsnext:main property. Currently, Steffi is only running her own source code through the babel-loader
Find out which module you have to include to be loaded through babel-loader. Check each dependency's package.json, see if it has a property jsnext:main
0

In bundle.js, line 77854, character 15, there is a parenthese after a object properties name, instead of a :. There must be something like :

{property () {}} 

instead of

{property : function () {}} 

Edit (thanks to @handoncloud): The first is valid ES6, and is a shorthand for the second, that is the equivalent in ES5.

The problem is, that the build does not fully support ES6.

12 Comments

Found it. I think it from the plugin React-Modal : i.imgur.com/uXYeBNr.png (bundle.js) — i.imgur.com/kvXZLw6.png (react-modal.js) But how to solve that ? It's not my code. I just compile it with webpack...
{property() {} } is something valid in ES6, just fyi (inside an object expression, not block statement). It's a shorthand method
@Steffi Are you talking about removePotal ? Maybe Babel is trying to compress that input as ES5 or below. This is totally valid in ES5 yes.
If ES6 isn't supported, then just define it with the regular function syntax.
Thanks guys, I understand better so what is the solution?
|
0

Found it.

React-Bootstrap-Table have a dependency named React-Modal.

I installed React Modal by npm install react-modal without --save or --save-dev. So React-Modal wasn't not listed in my package.json.

Now everything is ok.

SOLUTION : npm install react-modal --save

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.