Skip to content

Error: "Block-scoped declarations (let, const, function, class) not yet supported outside strict mode" #17

@mikelambert

Description

@mikelambert

I am getting the following error when adding this module to my project (tried searching around, but can't find anyone else with this problem on this module):

/myproject/node_modules/babel-plugin-react-autoprefix/index.js:10
  let binding
  ^^^

SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:374:25)
    at Module._extensions..js (module.js:417:10)
    at Object.require.extensions.(anonymous function) [as .js] (/myproject/node_modules/babel-register/lib/node.js:152:7)
    at Module.load (module.js:344:32)
    at Function.Module._load (module.js:301:12)
    at Module.require (module.js:354:17)
    at require (internal/module.js:12:17)
    at /myproject/node_modules/babel-core/lib/transformation/file/options/option-manager.js:174:20
    at Array.map (native)

Adding a 'use strict'; to the index.js helps it get a bit further:

/myproject/node_modules/babel-plugin-react-autoprefix/index.js:112
module.exports = ({ types: t }) => ({
                  ^

SyntaxError: Unexpected token {
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:374:25)
    at Module._extensions..js (module.js:417:10)
    at Object.require.extensions.(anonymous function) [as .js] (/myproject/node_modules/babel-register/lib/node.js:152:7)
    at Module.load (module.js:344:32)
    at Function.Module._load (module.js:301:12)
    at Module.require (module.js:354:17)
    at require (internal/module.js:12:17)
    at /myproject/node_modules/babel-core/lib/transformation/file/options/option-manager.js:174:20
    at Array.map (native)

Seems like it's using modern features, but the runtime is not expecting them. My .babelrc configuration is as follows:

{
  "presets": ["latest", "react", "stage-0"],
  "plugins": [
    "react-autoprefix",
    "react-hot-loader/babel",
    "transform-object-rest-spread",
    "transform-flow-strip-types",
    ["react-intl", {
        "messagesDir": "../build/messages/",
        "enforceDescriptions": true
    }],
  ],
  "retainLines": true
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions