smooth-scrollbar icon indicating copy to clipboard operation
smooth-scrollbar copied to clipboard

Compile error - when using rollup babel

Open magicspon opened this issue 7 years ago • 5 comments

Hello,

I'm getting a compile error when I import the module

[Compile Error] Unexpected token (4:20367) in /Users/magicspon/websites/mudstone/node_modules/smooth-scrollbar/dist/smooth-scrollbar.js

As the code is minified so I can't really see where it's failing. I'm not sure if this is an issue with rollup babel.

This is my rollup config (using gulp)

plugins: [
		resolve({
			jsnext: true,
			main: true,
			browser: true
		}),
		commonjs({
			include: 'node_modules/**'
		}),
		eslint({
			exclude: $js.lint.ignore
		}),
		babel({
			exclude: 'node_modules/**',
			presets: [
				'stage-0',
				['es2015', { 'modules': false }]
			],
			plugins: [
				'external-helpers',
				'syntax-object-rest-spread',
				'transform-es2015-parameters',
				'transform-es2015-destructuring',
				'transform-object-rest-spread'
			],
			babelrc: false,
			runtimeHelpers: true
		}),
		replace({
			ENV: JSON.stringify(process.env.NODE_ENV || 'development')
		}),
		(process.env.NODE_ENV === 'production' && uglify())
	]

Any ideas?

Thanks

magicspon avatar Dec 12 '16 23:12 magicspon

Sorry I'm not familiar with rollup, can you provide more details about the error outputs?

idiotWu avatar Dec 12 '16 23:12 idiotWu

Hello,

[Compile Error] Unexpected token (4:20367) in /Users/magicspon/websites/mudstone/node_modules/smooth-scrollbar/dist/smooth-scrollbar.js

I'm afraid that is the entire error message I get.

I made a clone of this repo, ran npm run dist with the ugilify stuff commented out and copied the output into my project node_modules.

I then got this error:

[22:57:40] gulp-notify: [Compile Error] Unexpected token (1783:35) in /Users/magicspon/websites/mudstone/node_modules/smooth-scrollbar/dist/smooth-scrollbar.js in

Line 1783 below

if (typeof _shared.GLOBAL_ENV.MutationObserver === 'function') {
	            // observe
	            var observer = new _shared.GLOBAL_ENV.MutationObserver(function () {
	                _this.update(true);  // <!---- LINE 183 
	            });
					
	            observer.observe(content, {
	                childList: true
	            });
					
	            Object.defineProperty(this, '__observer', {
	                value: observer
	            });
	        }

I can't see anything wrong with that snippet of code... I tried commenting it out to see if there were more errors, the next one was very similar, code looks totally fine.

[22:58:49] gulp-notify: [Compile Error] Unexpected token (1811:43) in /Users/magicspon/websites/mudstone/node_modules/smooth-scrollbar/dist/smooth-scrollbar.js in

line 1811 below:

_createClass(SmoothScrollbar, [{
	        key: 'MAX_OVERSCROLL',
	        get: function get() {
	            var options = this.options,
	                size = this.size;


	            switch (options.overscrollEffect) {
	                case 'bounce':
	                    var diagonal = Math.floor(Math.sqrt(Math.pow(size.container.width, 2) + Math.pow(size.container.height, 2)));
	                    var touchFactor = this.__isMovementLocked() ? 2 : 10;

	                    return _shared.GLOBAL_ENV.TOUCH_SUPPORTED ? (0, _utils.pickInRange)(diagonal / touchFactor, 100, 1000) : (0, _utils.pickInRange)(diagonal / 10, 25, 50);
										break;
	                case 'glow':
	                    return 150;  // <!-- LINE 1811

	                default:
	                    return 0;
	            }
	        }
	    }

very odd

I've made an example in this repo: https://github.com/magicspon/smooth-scrollbar-issue npm i npm run scripts

Cheers

magicspon avatar Dec 12 '16 23:12 magicspon

That is so weird...can you just exclude smooth-scrollbar from rollup until I can figure out what's going on?

idiotWu avatar Dec 13 '16 00:12 idiotWu

Hi,

I don't have a solution but I do have the same problem compiling with RollupJs

Unexpected token node_modules/smooth-scrollbar/dist/smooth-scrollbar.js (4:20359)

Fabrunet avatar May 22 '17 19:05 Fabrunet

8.0.0 is now published with pkg.module field. Can you try it again and see whether the problem is resolved?

idiotWu avatar Oct 08 '17 20:10 idiotWu

I used to integrate gulp with webpack (webpack-stream) or with rollup 🤣 If you still using gulp better look at this boilerplate and also update the package.json modules

https://github.com/jh3y/gulp-boilerplate


also, test smooth-scrollbar with rollup-starter-app it works without problem

rollup-starter-app.zip

sadeghbarati avatar Nov 11 '22 19:11 sadeghbarati