Skip to content
Advertisement

Attempted import error: ‘formatDate’ is not exported from ‘src/utils’

I am trying to create a utils file in React where it uses a library, but the exported function is not visible to other files with the following compilation error:

Attempted import error: 'formatDate' is not exported from 'src/utils'.

As soon as I remove the library, the code compiles and works greatly. Also, if I use the library code directly from my component the code compiles and works.

I have searched a lot to know what the problem is with exporting a function that is using a library but found nothing relevant.

import moment from 'moment';

exports.formatDate = (format, date) => {
  return moment(date).format(format);
}

Advertisement

Answer

Change

exports.formatDate = (format, date)

To

export const formatDate = (format, date) => {
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement