# Fix 'Cannot assign to read only property exports' in JS

> Fix the TypeError: Cannot assign to read only property exports error from Webpack by switching from CommonJS module.exports to ES Modules export default.

Author: [Flavio Copes](https://flaviocopes.com/about/) | Published: 2020-04-23 | Topics: [JavaScript](https://flaviocopes.com/tags/js/) | Canonical: https://flaviocopes.com/cannot-assign-readonly-property-export/

While working on a project, at some point I got this error: 

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

The error is generated by [Webpack](https://flaviocopes.com/webpack/) and it means you are trying to use [CommonJS](https://flaviocopes.com/commonjs/) while you need to use [ES modules](https://flaviocopes.com/es-modules/)!

Instead of using the CommonJS syntax:

```js
const myfunction = () => {}
module.exports = myfunction
```

use this ES Modules syntax: 

```js
const myfunction = () => {}
export default myfunction
```

Then you can import an exported function or object like this:

```js
import myfunction from './myfunction'
```

You can also export multiple functions or objects from a file:

> myfunctions.js 

```js
const myfunction1 = () => {}
const myfunction1 = () => {}

export {
  myfunction1,
  myfunction2
}
```

Then you can import them as:

```js
import { myfunction1, myfunction2 } from './myfunctions.js'
```
