reactjs – The requested module ‘react’ is expected to be of type CommonJS

I’m having this kind of error when I added this to my Next.js app

import { Fragment } from 'react'
import { Popover, Transition } from '@headlessui/react'
import { MenuIcon, XIcon } from '@heroicons/react/outline'

Node version is 14.6.0
Next version is 12.1.0

Here’s the full error message:

SyntaxError: The requested module ‘react’ is expected to be of type
CommonJS, which does not support named exports. CommonJS modules can
be imported by importing the default export.

I’ve tried to just use this instead but no luck:

import React from 'react'
import Headless from '@headlessui/react'
import HeadlessOutline from '@heroicons/react/outline'

And use it like React.Fragment or Headless.Transition

Read more here: Source link