Skip to content
New issue

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

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

Already on GitHub? # to your account

[Webpack 3?] Duplicate declaration error #611

Closed
Reinmar opened this issue Jun 30, 2017 · 4 comments
Closed

[Webpack 3?] Duplicate declaration error #611

Reinmar opened this issue Jun 30, 2017 · 4 comments
Labels
bug Confirmed bug

Comments

@Reinmar
Copy link

Reinmar commented Jun 30, 2017

I've been trying to isolate this error, but I think that it has something to do with Webpack 3 and I can't pull anything of value from Babili and Webpack.

However, you can reproduce this issue by:

git clone https://github.com/ckeditor/ckeditor5-build-classic.git
git co babili-webpack-error
npm i
npm run build-ckeditor

This is the output I get:

(babili-webpack-error b720deb) p@m /workspace/test/ckeditor5-build-classic> npm run build-ckeditor

> @ckeditor/ckeditor5-build-classic@0.2.0 build-ckeditor /workspace/test/ckeditor5-build-classic
> ./bin/build-ckeditor.sh

Building 'build/ckeditor.js'...

Hash: 50fb7c52c064ebfdf790
Version: webpack 3.0.0
Time: 3798ms
          Asset    Size  Chunks                    Chunk Names
    ckeditor.js  405 kB       0  [emitted]  [big]  main
ckeditor.js.map  484 kB       0  [emitted]         main
  [37] ./ckeditor.js 191 bytes {0} [built]
  [58] (webpack)/buildin/harmony-module.js 596 bytes {0} [built]
  [59] (webpack)/buildin/global.js 509 bytes {0} [built]
    + 88 hidden modules

ERROR in unknown: Duplicate declaration "count"

Done.

This is the Webpack config: https://github.com/ckeditor/ckeditor5-build-classic/blob/babili-webpack-error/webpack.config.js

And the crucial file is this one: https://github.com/ckeditor/ckeditor5-typing/blob/958eeb26c6d862de3cdfbf53efd0a554e3c8e13e/src/typing.js

It imports:

Which both depends on:

Both of these modules import count function and I think that this is that duplicated count identifier.

If I disable Babili plugin in webpack.config.js everything works fine. I also checked that builds done without Babili run correctly so most likely the issue is not on Webpack's side.

Output without Babili:

(babili-webpack-error b720deb M3) p@m /workspace/test/ckeditor5-build-classic> npm run build-ckeditor

> @ckeditor/ckeditor5-build-classic@0.2.0 build-ckeditor /workspace/test/ckeditor5-build-classic
> ./bin/build-ckeditor.sh

Building 'build/ckeditor.js'...

Hash: 50fb7c52c064ebfdf790
Version: webpack 3.0.0
Time: 759ms
          Asset    Size  Chunks                    Chunk Names
    ckeditor.js  405 kB       0  [emitted]  [big]  main
ckeditor.js.map  484 kB       0  [emitted]         main
  [37] ./ckeditor.js 191 bytes {0} [built]
  [58] (webpack)/buildin/harmony-module.js 596 bytes {0} [built]
  [59] (webpack)/buildin/global.js 509 bytes {0} [built]
    + 88 hidden modules

Done.

I've checked the unminified output but I can't find anything there which would suspiscious.

I'm using webpack 3.0.0 and babili-webpack-plugin 0.1.2.

@Reinmar
Copy link
Author

Reinmar commented Jun 30, 2017

Actually, there are just two places where count identifier is used in the Webpack's output:

/* 36 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {

"use strict";
/* harmony export (immutable) */ __webpack_exports__["a"] = count;
/**
 * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
 * For licensing, see LICENSE.md.
 */

/**
 * @module utils/count
 */

/**
 * Returns the number of items return by the iterator.
 *
 *		count( [ 1, 2, 3, 4, 5 ] ); // 5;
 *
 * @param {Iterable.<*>} iterator Any iterator.
 * @returns {Number} Number of items returned by that iterator.
 */
function count( iterator ) {
	let count = 0;

	for ( let _ of iterator ) { // jshint ignore:line
		count++;
	}

	return count;
}


/***/ })

And:

	insertChildren( index, nodes ) {
		this._fireChange( 'children', this );
		let count = 0;

		nodes = normalize( nodes );

		for ( let node of nodes ) {
			node.parent = this;

			this._children.splice( index, 0, node );
			index++;
			count++;
		}

		return count;
	}

The first is that imported count() function, so it's most likely it.

@vigneshshanmugam vigneshshanmugam added the bug Confirmed bug label Jun 30, 2017
@vigneshshanmugam
Copy link
Member

Thanks for the detailed writeup. Seems to a bug in DCE.

@boopathi
Copy link
Member

Duplicate of #226 . That got fixed. But looks like it has reappeared.

minimal repro:

function foo() {
  function count(it) {
    let count = 1;
    for(;it();) {
      count++;
    }
    return count;
  }
  return count;
}

vigneshshanmugam pushed a commit that referenced this issue Jul 11, 2017
* Detect duplicate declaration during one-use replacement

Fix #611

* FnDecls always have id
@Tarnadas
Copy link

Tarnadas commented Jul 13, 2017

Is a build with that fix already published on npm? I just updated and still get the error.

export default function x () {
  let x
}

throws for me a duplicate declaration error

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Confirmed bug
Projects
None yet
Development

No branches or pull requests

4 participants