contentlayer: Eslint Error: Unable to resolve path to module 'next-contentlayer'

Hi. I can’t import anything from ‘next-contentlayer’:

const { withContentlayer } = require('next-contentlayer');
error - Failed to load next.config.js, see more info here https://nextjs.org/docs/messages/next-config-error
ReferenceError: withContentLayer is not defined

The same for:

import { useMDXComponent } from 'next-contentlayer/hooks';

Eslint shows:

Unable to resolve path to module 'next-contentlayer/hooks'

Package.json:

   "contentlayer": "0.0.32",
   "next-contentlayer": "0.0.32",

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 16

Most upvoted comments

Just a tip for everyone who has the same issue. You can create a ignore rule in your .eslintrc.json to fix this issue for the entire project:

{
  "rules": {
    "import/no-unresolved": [
      2,
      {
        "ignore": [
          "contentlayer/generated",
          "next-contentlayer/hooks"
        ]
      }
    ]
  }
}

@juanpmd I think your issue is with react 18. Downgrading to 17 will fix it @schickling I’m sorry, I’m drowning in work. Yes, I’m still having this issue. I see you’re running the dev server. Can you try building it?