Latest Babel (@babel/core v7) error "exports is not defined"

9.8k Views Asked by At

I've tried everything i could find so far and i'm still getting the error "exports is not defined".

I am using ReactJS.NET (for NetCore2) and it is mandatory otherwise my entire app will not load under NetCore2.

This is my .babelrc

{
  "presets": [
    "@babel/preset-react",
    "@babel/preset-env",
    "@babel/preset-typescript"
  ],
  "plugins": [
    "add-module-exports",
    "@babel/plugin-proposal-class-properties",
    [
      "@babel/plugin-transform-runtime",
      {
        "corejs": 2,
        "helpers": true,
        "regenerator": true,
        "useESModules": true
      }
    ]
  ]
} 

Everything worked fine with the older babel and "add-module-exports". Is there an alternative for babel 7?

1

There are 1 best solutions below

2
On BEST ANSWER

A couple of things:

Update

I did not notice that you are using typescript. In that case, you probably want to do this instead:

1) Change your .babelrc to:

{
  "presets": [
    "react",
    ["env", {"modules": false} ],
    "typescript"
  ],
  "plugins": [
    "add-module-exports",
    "@babel/plugin-proposal-class-properties",
    [
      "@babel/plugin-transform-runtime",
      {
        "corejs": 2,
        "helpers": true,
        "regenerator": true,
        "useESModules": true
      }
    ]
  ]
}

2) make sure that your tsconfig.json has the following entry: "module": "commonjs",