Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

`Duplicate declaration` error in 7.0.0 with decorators, nested functions, ES6 modules, and a node target #8559

dantman opened this issue Aug 28, 2018 · 7 comments


None yet
6 participants
Copy link

commented Aug 28, 2018

Bug Report

Current Behavior
Transpilation of the code fails with the following error.

TypeError: .../babel-duplicate-definition-error/index.js: Duplicate declaration "Foo"
  3 | export default function wrap() {
  4 |   return function() {
> 5 |           class Foo {
    |                 ^
  6 |                   @autobind
  7 |                   method() {}
  8 |           }
    at File.buildCodeFrameError (/private/tmp/babel-duplicate-definition-error/node_modules/@babel/core/lib/transformation/file/file.js:259:12)
    at Scope.checkBlockScopedCollisions (/private/tmp/babel-duplicate-definition-error/node_modules/@babel/traverse/lib/scope/index.js:347:22)
    at Scope.registerBinding (/private/tmp/babel-duplicate-definition-error/node_modules/@babel/traverse/lib/scope/index.js:504:16)
    at Scope.registerDeclaration (/private/tmp/babel-duplicate-definition-error/node_modules/@babel/traverse/lib/scope/index.js:444:14)
    at Object.BlockScoped (/private/tmp/babel-duplicate-definition-error/node_modules/@babel/traverse/lib/scope/index.js:189:28)
    at Object.newFn (/private/tmp/babel-duplicate-definition-error/node_modules/@babel/traverse/lib/visitors.js:230:17)
    at NodePath._call (/private/tmp/babel-duplicate-definition-error/node_modules/@babel/traverse/lib/path/context.js:53:20)
    at (/private/tmp/babel-duplicate-definition-error/node_modules/@babel/traverse/lib/path/context.js:36:14)
    at NodePath.visit (/private/tmp/babel-duplicate-definition-error/node_modules/@babel/traverse/lib/path/context.js:88:12)
    at TraversalContext.visitQueue (/private/tmp/babel-duplicate-definition-error/node_modules/@babel/traverse/lib/context.js:118:16)

Input Code
Executable gist:

  • Must use @babel/preset-env with a target like node: 8
  • Must use @babel/plugin-proposal-decorators with legacy: true
import {autobind} from 'core-decorators';

export default function wrap() {
	return function() {
		class Foo {
			method() {}

		return Foo;

Expected behavior/code
A clear and concise description of what you expected to happen (or code).

Babel Configuration (.babelrc, package.json, cli command)

  "presets": [
        "targets": {
          "node": 8
  "plugins": [
    ["@babel/plugin-proposal-decorators", {"legacy": true}]
  "scripts": {
    "start": "babel index.js"
  "devDependencies": {
    "@babel/cli": "^7.0.0",
    "@babel/core": "^7.0.0",
    "@babel/plugin-proposal-decorators": "^7.0.0",
    "@babel/preset-env": "^7.0.0"
  "dependencies": {
    "core-decorators": "^0.20.0"
npm install
npm start # babel index.js


  • Babel version(s): v7.0.0
  • Node/npm version: Tested and confirmed in Node 8/9/10 with npm 5.6.0
  • OS: OSX 10.12.16
  • Monorepo: no
  • How you are using Babel: cli and jest

Additional context
#8525 may be related, however I'm reporting it separately because this error happens with a different type of code and does not have "(This is an error on an internal node. Probably an internal error.)" in the error message.

If you make any of the following changes the error goes away:

  • Remove the @autobind decorator
  • Remove the export default
  • Remove the return function() {} so that wrap returns Foo directly.
  • Remove the node target from env (i.e. change the target so env does not emit a number of transforms)

This comment has been minimized.

Copy link

commented Aug 28, 2018

Hey @dantman! We really appreciate you taking the time to report an issue. The collaborators
on this project attempt to help as many people as possible, but we're a limited number of volunteers,
so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack
community that typically always has someone willing to help. You can sign-up here
for an invite.


This comment has been minimized.

Copy link

commented Aug 28, 2018

@babel/plugin-proposal-decorators and @babel/plugin-transform-modules-commonjs are enough to reproduce the bug.

@semireg semireg referenced this issue Nov 1, 2018


Feature request: support Babel 7 #184

3 of 3 tasks complete

This comment has been minimized.

Copy link

commented Jan 31, 2019

Can confirm that this is still an issue.


This comment has been minimized.

Copy link

commented Apr 24, 2019

when targets: { node: '5.12.0' } babel can work well.
with node version > 6.0.0 this is still an issue, can anyone fix it?


This comment has been minimized.

Copy link

commented May 31, 2019

@dantman do you figure out anyway to workaround this issue?


This comment has been minimized.

Copy link

commented May 31, 2019

@thinkkevin I don't remember what project I had this issue on.


This comment has been minimized.

Copy link

commented May 31, 2019

@dantman never mind.
I tried to remove the export default and add such in the end of file, which seems working fine.

Thank you for such detail information in the report. It helps a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.