Scott Myers
Scott Myers

Reputation: 202

Cannot assign to read only property 'exports' of object ERROR after upgrading to Babel 7

Getting the following error after upgrading to Babel 7 in my react app. Let me know if I need to include more details!

I've tried the solution of replacing module.exports with export default but that brings other errors.

Error:

module.exports = {
^

TypeError: Cannot assign to read only property 'exports' of object '#<Object>'

  23 | const host = process.env.RAZZLE_HOST || `http://localhost:${port}`;
  24 | 
> 25 | module.exports = {
  26 |   port,
  27 |   host,
  28 |   isAdminSite,

config.js context:

const host = process.env.RAZZLE_HOST || `http://localhost:${port}`;

module.exports = {
  port,
  host,
  isAdminSite,
  adminSiteUrl,
  userSiteUrl,

Imported like:

import _ from 'lodash';
import moment from 'moment-timezone';
import splitLinks from '../helpers/split-links';
import { host } from '../config';
import MatchView from './match_view';```

Upvotes: 1

Views: 5021

Answers (1)

Aritra Chakraborty
Aritra Chakraborty

Reputation: 12542

Basically, You can mix require and export.

export {
 someObj
}
//and then import by

require('./file.js')

But you cannot mix: import with module.exports it won't work.

So, in your case, the module.exports needs to be export or import needs to be require.

Upvotes: 2

Related Questions