Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module not found: Can't resolve 'child_process' #210

Closed
vannyle opened this issue Nov 17, 2021 · 7 comments
Closed

Module not found: Can't resolve 'child_process' #210

vannyle opened this issue Nov 17, 2021 · 7 comments
Labels
support questions requesting support

Comments

@vannyle
Copy link

vannyle commented Nov 17, 2021

With the version "next-mdx-remote": "3.0.8", I'm facing with the error below:

./node_modules/esbuild/lib/main.js:1567:0
Module not found: Can't resolve 'child_process'
null

I use the mdx-remote in the same file, where the getStaticPaths and getStaticProps were used:

import {CTA} from 'LandingPage/CTA'
import {CTAWithImage} from '../CTAWithImage/index'
import fs from 'fs'
import {getPageBySlug} from 'LandingPage/common/helpers'
import {GlobalBasicMeta} from 'common/GlobalBasicMeta'
import Head from 'next/head'
import {Hero} from 'LandingPage/Hero'
import {LandingLayout} from 'common/LandingLayout'
import {memo} from 'react'
import {Newsletter} from 'LandingPage/Newsletter'
import path from 'path'
import {Post as PostType} from '../common/types/posts'
import {serialize} from 'next-mdx-remote/serialize'
import {MDXRemote} from 'next-mdx-remote'

export const Details = memo(function Details(props: {
  post: PostType
}) {
  const components = {CTA, CTAWithImage, Hero, Newsletter}
  return <LandingLayout>
    <GlobalBasicMeta />

    <MDXRemote {...props.post.content} components={components} />

  </LandingLayout>
})

export const getStaticProps = async ({params}) => {
  const post = getPageBySlug(params.slug)
 
  return {
    props: {post: {
      ...post,
      content: await serialize(post.content),
    }},
  }
}

export const getStaticPaths = async () => {
  const files = fs.readdirSync(path.join('landing-pages'))

  const paths = files.map(filename => ({
    params: {
      slug: filename.replace(/\.md$/, ''),
    },
  }))

  return {
    fallback: false,
    paths,
  }
}

Does anyone have a solution for this issue?

@jescalan
Copy link
Collaborator

What is your deployment environment?

@jescalan jescalan added the support questions requesting support label Nov 18, 2021
@vannyle
Copy link
Author

vannyle commented Nov 18, 2021

@jescalan Hi, it is the local dev environment. And the node version is v14.18.0.

@jescalan
Copy link
Collaborator

Okok - could you create a minimal reproduction repo and post it here? I can pull it down and take a look : )

@sebahhpeya
Copy link

sebahhpeya commented Dec 17, 2021

Same issue here!

i'm changed to version 2 again because i couldn't solve it.

Just create a next application in 10 version and use mdx with your exmple code here

@tusharpandey13
Copy link

This seems to work for me in dev (I'm kinda new to this so I don't know if this fixes the problem or just hides it):

/// next.config.js
module.exports = {
  webpack5: true,
  webpack: (config, { isServer }) => {
    if (!isServer) {
      config.resolve.fallback.fs = false;
      config.resolve.fallback.child_process = false;
      config.resolve.fallback.worker_threads = false;
    }
    return config;
  },

  reactStrictMode: true,
};

I was getting similar module not found errors for fs and child_process as well.
I referenced this issue thread.

@fboechats
Copy link

That's because you have client side and server side content in the same file. If you extract that Details component it should work fine

@BRKalow
Copy link
Contributor

BRKalow commented Mar 21, 2022

Closing this, please feel free to open another issue or drop a comment if you're still having troubles here. Thanks!

@BRKalow BRKalow closed this as completed Mar 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
support questions requesting support
Projects
None yet
Development

No branches or pull requests

6 participants