Skip to content
This repository has been archived by the owner on Mar 15, 2020. It is now read-only.

Error when minifying dynamic import #137

Closed
sansSpoon opened this issue Nov 21, 2018 · 2 comments · Fixed by #141
Closed

Error when minifying dynamic import #137

sansSpoon opened this issue Nov 21, 2018 · 2 comments · Fixed by #141
Labels
Milestone

Comments

@sansSpoon
Copy link

sansSpoon commented Nov 21, 2018

Steps to reproduce the issue

  1. run rollup build without rollup-plugin-babel-minify, build successful
  2. add minify and get the error
src/index.js → public/module...
[!] (babel-minify plugin) SyntaxError: Error transforming bundle with 'babel-minify' plugin: unknown: Support for the experimental syntax 'dynamicImport' isn't currently enabled (94:7):

  92 |     key: "handleClick",
  93 |     value: function handleClick() {
> 94 |       import("./moduleA.js").then(function (module) {
     |       ^
  95 |         console.log(module.default);
  96 |       }).catch(function (err) {// Handle failure
  97 |       });

Add @babel/plugin-syntax-dynamic-import (https://git.io/vb4Sv) to the 'plugins' section of your Babel config to enable parsing.
undefined (94:6)
SyntaxError: Error transforming bundle with 'babel-minify' plugin: unknown: Support for the experimental syntax 'dynamicImport' isn't currently enabled (94:7):

Babelrc is:

{
	"presets": [
		["@babel/env", {
			"modules": false
		}],
		["@babel/preset-react"]
	],
	"plugins": [
		["@babel/plugin-syntax-dynamic-import"]
	]
}

Running Babel via CLI babel src/App.js -o compiled.js with the following babelrc is successful:

{
	"presets": [
		["@babel/env", {
			"modules": false
		}],
		["@babel/preset-react"],
		["minify", {
			"mangle": {
				"topLevel": true,
			}
		}]
	],
	"plugins": [
		["@babel/plugin-syntax-dynamic-import"]
	]
}

Version of package: 6.1.1
Node.js & npm versions: 11.0.0, 6.4.1
Operating system: macOS 10.13.6

@Comandeer Comandeer added the bug label Nov 21, 2018
@Comandeer Comandeer added this to the v6.2.0 milestone Nov 21, 2018
@Comandeer
Copy link
Owner

It's caused by the fact that ATM rollup-plugin-babel-minify does not support adding additional plugins to Babel. I'm going to add such ability (see #138), which should fix also this error.

Please note also that ATM .babelrc file is not supported and all configuration has to be passed as configuration option to the plugin itself.

@Comandeer
Copy link
Owner

I just released 6.2.0, which should fix the issue. Now you can pass needed plugin as an option to the rollup-plugin-babel-minify. Example rollup.config.js:

import minify from 'rollup-plugin-babel-minify';

export default {
	input: 'index.js',
	plugins: [
		minify( {
			plugins: [
				'@babel/plugin-syntax-dynamic-import'
			]
		} )
	],
	output: {
		sourcemap: true,
		file: 'bundle.js',
		format: 'es'
	}
};

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants