Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RollupJS error on file util/isArrayLike.js #2403

Closed
noemi-salaun opened this issue Feb 22, 2017 · 9 comments
Closed

RollupJS error on file util/isArrayLike.js #2403

noemi-salaun opened this issue Feb 22, 2017 · 9 comments

Comments

@noemi-salaun
Copy link

RxJS version:
5.2.0

Code to reproduce:
Run RollupJS in a project that uses RxJS.
Use rollup plugin rollup-plugin-commonjs with config

plugins  : [
        commonjs({
            include     : [
                'node_modules/rxjs/**'
            ]
        }
]

Expected behavior:
Bundling with RollupJS should work

Actual behavior:

Error: Unexpected token
node_modules/rxjs/util/isArrayLike.js (2:78)
1: "use strict";
2: var isArrayLike_1 = function (x) { return x && typeof x.length === 'number'; });
                                                                                 ^
3: //# sourceMappingURL=isArrayLike.js.map

Additional information:
Just removing the parenthesis works for me.

Replace :

exports.isArrayLike = (function (x) { return x && typeof x.length === 'number'; });

with :

exports.isArrayLike = function (x) { return x && typeof x.length === 'number'; };
@kwonoj
Copy link
Member

kwonoj commented Feb 22, 2017

So this seems like isArrayLike is wrapped with parenthesis
export const isArrayLike = (<T>(x: any): x is ArrayLike<T> => x && typeof x.length === 'number');,

but it brings curiousity if it doesn't work with any other codes like this - @noemi-salaun , would you able to try out cjs equivalent such as

const isArrayLike = ((x) => x && typeof x.length === 'number');

and given rollup-plugin-commonjs can consume those as well?

kwonoj added a commit to kwonoj/rxjs that referenced this issue Feb 22, 2017
@noemi-salaun noemi-salaun changed the title RollupJS error on util/isArrayLike RollupJS error on file util/isArrayLike.js Feb 22, 2017
@noemi-salaun
Copy link
Author

I tried with isArrayLike.js looking like :

"use strict";
exports.isArrayLike = ((x) => x && typeof x.length === 'number');
//# sourceMappingURL=isArrayLike.js.map

but it's the same error

Error: Unexpected token
node_modules/rxjs/util/isArrayLike.js (2:60)
1: "use strict";
2: var isArrayLike_1 = (x) => x && typeof x.length === 'number');
                                                               ^
3: //# sourceMappingURL=isArrayLike.js.map

But it seems that rollup-plugin-commonjs can handle it.

So I tried without parenthesis :

"use strict";
exports.isArrayLike = (x) => x && typeof x.length === 'number';
//# sourceMappingURL=isArrayLike.js.map

It works but rollup-plugin-uglify does not like it

Error: (uglify plugin) Error transforming bundle with 'uglify' plugin: SyntaxError: Unexpected token: operator (>)

@kwonoj
Copy link
Member

kwonoj commented Feb 22, 2017

Hm, seems my PR is premature and probably won't work as workaround.

I'm feeling this is more like rollup side issues, since given module is simple function export and should be able to be consumed. Does rollup confirms it's expected behavior on rollup side? If not, I'd like to suggest check with rollup as well. I assume given error can be reproducible without depends on Rx.

@noemi-salaun
Copy link
Author

Hm no, I didn't check with rollup people.

I will ask them to see if the issue come from there side.

Thank you for the fast reply 😄

@noemi-salaun
Copy link
Author

noemi-salaun commented Feb 22, 2017

Hu, someone already takes care of it.

rollup/rollup-plugin-commonjs#168

@kwonoj
Copy link
Member

kwonoj commented Feb 22, 2017

@noemi-salaun Cool. Let me close this issue for now, feel freely reopen once rollup clarifies if it isn't related with rollup's behavior but need RxJS side code changes.

@kwonoj kwonoj closed this as completed Feb 22, 2017
@blagerweij
Copy link

This is not a rollup bug, but rxjs. Reverting to version 5.1.1 of rxjs fixes it, since 5.2.0 the problem exists. If you remove the round brackets, it's also fine. Right now this issue is closed, as well as the rollup issue (#168). I suggest this is fixed in rxjs, please re-open the issue and remove the round brackets in isArrayLike function.

@noemi-salaun
Copy link
Author

There isn't the issue with rxjs 5.1.1 because there isn't the file util/isArrayLike.js before version 5.2.0.
The parenthesis aren't the problem, it's the way rollup-plugin-commonjs parse it.

@lock
Copy link

lock bot commented Jun 6, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants