Skip to content

[Babel] Not working for imports from node_modules #594

@varunsridharan

Description

@varunsridharan

Hi All,

i just discovered RollUP and it works great :-)

But i am just stuck with an issue where Babel dose not run for imports from node_modules

Here is an example

My Javascript Code

import { _map } from "@varunsridharan/js-vars"
const myarray = _map.call([1,2,3,4],(x)=> x * 2);
console.log(myarray);

Rollup Config

import { babel } from '@rollup/plugin-babel';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import { uglify } from 'rollup-plugin-uglify';
import filesize from 'rollup-plugin-filesize';
import visualizer from 'rollup-plugin-visualizer';

export default {
	input: './src/index.js',
	output: {
		file: './dist/myfile.min.js',
		format: 'iife',
		plugins: [
			uglify( { mangle: true } ),
		]
	},
	plugins: [
		nodeResolve(),
		babel(),
		filesize(),
		visualizer()
	]
};

when i run rollup -c in CLI i get the below output
https://s2.do-spaces.com/2020/Sep/30/1601479998-194.jpg

babelHelpers: 'bundled' option was used by default. It is recommended to configure this option explicitly, read more here: https://github.com/rollup/plugins/tree/master/packages/babel#babelhelpers
  198 |          * Array Related Vars.
  199 |          */
> 200 |         const Arr = Array;
      | ^ Unexpected token: keyword «const»
  201 |         const _Arrayprop = Arr.prototype;
  202 |         const _filter = _Arrayprop.filter;
  203 |         const _push = _Arrayprop.push;
[!] (plugin uglify) Error: Unexpected token: keyword «const»
SyntaxError: Unexpected token: keyword «const»
    at JS_Parse_Error.get (eval at <anonymous> (E:\localhost\www\javascript\dizzle\node_modules\uglify-js\tools\node.js:18:1), <anonymous>:69:23)
    at reportError (E:\localhost\www\javascript\dizzle\node_modules\jest-worker\build\workers\processChild.js:107:11)
    at reportClientError (E:\localhost\www\javascript\dizzle\node_modules\jest-worker\build\workers\processChild.js:87:10)
    at execFunction (E:\localhost\www\javascript\dizzle\node_modules\jest-worker\build\workers\processChild.js:157:5)
    at execHelper (E:\localhost\www\javascript\dizzle\node_modules\jest-worker\build\workers\processChild.js:139:5)
    at execMethod (E:\localhost\www\javascript\dizzle\node_modules\jest-worker\build\workers\processChild.js:143:5)
    at process.<anonymous> (E:\localhost\www\javascript\dizzle\node_modules\jest-worker\build\workers\processChild.js:64:7)
    at process.emit (events.js:315:20)
    at emit (internal/child_process.js:876:12)
    at processTicksAndRejections (internal/process/task_queues.js:85:21)

Based on the output i was able to understand that babel did not run for the imported modules. so i checking the options provided for rollup babel plugin @ (https://github.com/rollup/plugins/tree/master/packages/babel) and found that it has include AND exclude options and i tried with the below config

babel( {
    include: [ "node_modules/@varunsridharan/*/**", "./src/**" ],
    exclude: "node_modules/**",
} ),

Still nothing happened so i tried without ./src/** in babel include config and found that babel is not running in my main javascript file which imports the node_modules's file

Node Module Project Link : https://github.com/varunsridharan/js-vars

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions