Issue 1:
Do you want to request a feature or report a bug?

Bug

Asked this question in SO and gitter but no proper answer.

What is the current behavior?

I used dynamic imports(import()) feature in my application like following.

// Make reducers hot reloadable, see http://mxs.is/googmo
/* istanbul ignore next */
if (module.hot) {
module.hot.accept('./reducers', () => {
import('./reducers').then((reducerModule) => {
const createReducers = reducerModule.default;
const nextReducers = createReducers(store.asyncReducers);

store.replaceReducer(nextReducers);
});
});
}

I also have babel stage-0 preset added which is expected to have dynamic imports babel plugin. I used webpack 2.5.1 before upgrading webpack 3.6.0 recently. Everything worked fine even after upgrade.

I wanted to add scope hoisting feature for which added new webpack.optimize.ModuleConcatenationPlugin() in my production webpack config. This started throwing following error for all dynamic imports.

ERROR in chunk main [entry]
[name].[chunkhash].js
'import' and 'export' may only appear at the top level (42:6)
| if (false) {
| module.hot.accept('./reducers', function () {
| import('./reducers').then(function (reducerModule) {
| var createReducers = reducerModule.default;
| var nextReducers = createReducers(store.asyncReducers);

Able to resolve the error with System.import. But that is deprecated and better way to do is with import() since it's in stage-3 now.

If the current behavior is a bug, please provide the steps to reproduce.

What is the expected behavior?

Should not throw any error

If this is a feature request, what is motivation or use case for changing the behavior?

Please mention other relevant information such as the browser version, Node.js version, webpack version and Operating System.

webpack version: 3.6.0

nodejs: 6.11.1

Issue 2:
What is the current behavior?

Running a module with if(...) { import().then(...) } through ModuleConcatenationPlugin results in an Acorn exception with Webpack 3.5.2. The module has been run through Babel w/ babel-preset-env and modules=false.

ERROR in chunk global [initial]
[name].[hash].js
'import' and 'export' may only appear at the top level (112:2)
|
| if (false) {
| import('react-addons-perf').then(function (Perf) {
| window.Perf = Perf;
| });
SyntaxError: 'import' and 'export' may only appear at the top level (112:2)
|
| if (false) {
| import('react-addons-perf').then(function (Perf) {
| window.Perf = Perf;
| });
at Parser.pp$4.raise (~/node_modules/webpack/node_modules/acorn/dist/acorn.js:2610:13)
at Parser.pp$1.parseStatement (~/node_modules/webpack/node_modules/acorn/dist/acorn.js:780:16)
at Parser.pp$1.parseBlock (~/node_modules/webpack/node_modules/acorn/dist/acorn.js:1076:23)
at Parser.pp$1.parseStatement (~/node_modules/webpack/node_modules/acorn/dist/acorn.js:774:34)
at Parser.pp$1.parseIfStatement (~/node_modules/webpack/node_modules/acorn/dist/acorn.js:901:26)
at Parser.pp$1.parseStatement (~/node_modules/webpack/node_modules/acorn/dist/acorn.js:763:31)
at Parser.pp$1.parseTopLevel (~/node_modules/webpack/node_modules/acorn/dist/acorn.js:690:23)
at Parser.parse (~/node_modules/webpack/node_modules/acorn/dist/acorn.js:543:15)
at Object.parse (~/node_modules/webpack/node_modules/acorn/dist/acorn.js:3669:37)
at modulesWithInfo.forEach.info (~/node_modules/webpack/lib/optimize/ConcatenatedModule.js:418:18)
at Array.forEach (<anonymous>)
at ConcatenatedModule.source (~/node_modules/webpack/lib/optimize/ConcatenatedModule.js:411:19)
at ModuleTemplate.render (~/node_modules/webpack/lib/ModuleTemplate.js:14:31)
at ~/node_modules/webpack/lib/Template.js:116:28
at Function.from (native)
at Chunk.mapModules (~/node_modules/webpack/lib/Chunk.js:163:16)
at ChunkTemplate.renderChunkModules (~/node_modules/webpack/lib/Template.js:113:26)
at ChunkTemplate.render (~/node_modules/webpack/lib/ChunkTemplate.js:16:30)
at Compilation.createChunkAssets (~/node_modules/webpack/lib/Compilation.js:1290:35)
at sealPart2 (~/node_modules/webpack/lib/Compilation.js:646:10)
at next (~/node_modules/tapable/lib/Tapable.js:202:11)
at Compilation.compilation.plugin (~/node_modules/webpack/lib/ProgressPlugin.js:111:6)
at Compilation.applyPluginsAsyncSeries (~/node_modules/tapable/lib/Tapable.js:206:13)
at Compilation.seal (~/node_modules/webpack/lib/Compilation.js:596:8)
at applyPluginsParallel.err (~/node_modules/webpack/lib/Compiler.js:514:17)
at ~/node_modules/tapable/lib/Tapable.js:289:11
at _addModuleChain (~/node_modules/webpack/lib/Compilation.js:498:11)
at processModuleDependencies.err (~/node_modules/webpack/lib/Compilation.js:468:14)
at _combinedTickCallback (internal/process/next_tick.js:131:7)
at process._tickCallback (internal/process/next_tick.js:180:9)

If the current behavior is a bug, please provide the steps to reproduce.

I'm unfortunately unable to reproduce this using a minimal repo – a minimal repo I tried to make works fine ☹️

What is the expected behavior?

No crashing :)

Naturally the workaround is to disable ModuleConcatenationPlugin.