1

I have a nextjs app with redux.

When I try to use the ?? operator in my pages/index, it works as it should.

I then tried to load up a redux store with a bunch of reducers. When I hit the ?? in a reducer file, I get this error:

Support for the experimental syntax 'optionalChaining' isn't currently enabled (71:32):

I also get the error in any other file: component, actions and reducers. It is only directly in the pages/* that the plugin is working properly.

My app is using next@9.1.1 and redux@4.0.4. Here is my .babelrc file:

  "env": {
    "development": {
      "presets": ["next/babel"],
      "plugins": [
        "@babel/plugin-proposal-optional-chaining",
        "@babel/plugin-proposal-nullish-coalescing-operator",
        [
          "styled-components",
          { "ssr": true, "displayName": true, "preprocess": false }
        ]
      ]
    }
  }
}

Is there something that would override my babel config for certain files? If so, what am I missing? What else should I look at?

jhamm
  • 24,124
  • 39
  • 105
  • 179
  • What do you mean by `??` operator? This? https://stackoverflow.com/questions/476436/is-there-a-null-coalescing-operator-in-javascript If so, you could just use `||`. You error could mean that the first `?` is interpreted as ternary operator, and the next `?` as Typescript's "optional chaining" operator. – timotgl Nov 30 '19 at 12:58
  • https://github.com/tc39/proposal-nullish-coalescing. The optional chaining is throwing the same errors. This is a very large project that already has lots of this syntax in it, so I don't want to have to convert anything when the js should be working as is with the proper babel plugins. – jhamm Nov 30 '19 at 14:21

0 Answers0