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

Block-scoped declarations not yet supported outside strict mode #168

Closed
01binary opened this issue Oct 13, 2016 · 1 comment
Closed

Block-scoped declarations not yet supported outside strict mode #168

01binary opened this issue Oct 13, 2016 · 1 comment

Comments

@01binary
Copy link

I am getting the following error when running mocha unit tests:

Block-scoped declarations (let, const, function, class) not yet supported outside strict mode

This is being caused by babel-register attempting to compile:

let __RewireAPI__ = {};

My interpretation of this error is that because we have 'use strict' at the top of all modules, the code injected by babel-plugin-rewire (which contains let __RewireAPI__ = {}; somewhere) causes an error when compiled by babel-register because let is not supported in strict mode.

The closest issue that describes something similar is this one:
#71 (comment)

Some kind of related commit is here:
ddfea82

As you can tell, I don't have a good eagle-eye view of the whole babel pipeline, so it's hard to reason about what's going wrong at which stage. In my package.json I have:

"babel-plugin-rewire": "^1.0.0"

Perhaps I got an old version from NPM because the package was renamed, and the fix for my issue is in a new version somewhere?

Thank you!

@01binary
Copy link
Author

01binary commented Oct 14, 2016

Adding transform-es2015-block-scoping plug-in before babel-plugin-rewire in .babelrc appears to have fixed this issue. I also added the require for babel-plugin-rewire in our Gruntfile.js to have mocha load the plug-in when running unit tests (otherwise it wasn't able to find the definition for Rewire, etc).

For posterity...

Before

.babelrc

{
    "presets": ["react"]
    "plugins": ["babel-plugin-rewire"]
}

Gruntfile.js

mochaTest: {
            unit: {
                src: src.testjs,
                options: {
                    clearRequireCache: true,
                    reporter:'mocha-jenkins-reporter',
                    reporterOptions: {
                        'junit_report_path': require('path').join('results/', 'mocha-unit.xml')
                    },
                    require: [
                        'babel-register',
                        'setup.js'
                    ]
                }
            }
        },

After

.babelrc

{
    "presets": ["react"],
    "plugins": ["transform-es2015-block-scoping", "babel-plugin-rewire"]
}

Gruntfile.js

mochaTest: {
            unit: {
                src: src.testjs,
                options: {
                    clearRequireCache: true,
                    reporter:'mocha-jenkins-reporter',
                    reporterOptions: {
                        'junit_report_path': require('path').join('results/', 'mocha-unit.xml')
                    },
                    require: [
                        'babel-register',
                        'babel-plugin-rewire',
                        'setup.js'
                    ]
                }
            }
        },

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

No branches or pull requests

1 participant