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

ModuleError: Cannot Resolve 'fs' used in markdown blog-starter example #20814

Closed
dillionmegida opened this issue Jan 6, 2021 · 6 comments
Closed
Labels
please add a complete reproduction The issue lacks information for further investigation

Comments

@dillionmegida
Copy link

What version of Next.js are you using?

9.5.1

What version of Node.js are you using?

12.18.4

What browser are you using?

Chrome

What operating system are you using?

macOS

How are you deploying your application?

Vercel

Describe the Bug

Following the markdown blog starter, the fs module was used in the lib/api.js file to do some reading from a directory.

On running npm run dev, and accessing the blog page, I get:

event - build page: /blog/[slug]
event - build page: /blog/[slug]
event - compiled successfully
error - ./utils/posts/index.ts
Module not found: Can't resolve 'fs' in ...

Expected Behavior

I followed everything in the blog-starter, so I expected the page to load without errors.

To Reproduce

The markdown blog starter template was what I used before getting the error.

Actually, I discovered a solution that worked for me, but I'm just surprised that the blog-starter did not use the solution.

In this discussion, the solution was to have a next.config.js configured like so:

module.exports = {
  webpack: (config, { isServer }) => {
    // Fixes npm packages that depend on `fs` module
    if (!isServer) {
      config.node = {
        fs: 'empty'
      }
    }

    return config
  }
}

But the blog starter did not have any next.config.js file so I'm wondering how it deployed successfully.

I've got the solution already but I think the starter working without the next config file should be addressed documentation-wise or any ways at all.

Awesome job, team. Thank you!

@dillionmegida dillionmegida added the bug Issue was opened via the bug report template. label Jan 6, 2021
@Timer Timer added please add a complete reproduction The issue lacks information for further investigation and removed bug Issue was opened via the bug report template. labels Jan 6, 2021
@Timer
Copy link
Member

Timer commented Jan 6, 2021

This was likely caused by an edit you made to the example. Could you please share your project?

@dillionmegida
Copy link
Author

Hi @Timer, the project is currently private in development. I'm sorry I can't share.
But I followed the blog-starter template and expected it to work without further configurations.

@Timer
Copy link
Member

Timer commented Jan 6, 2021

It does work fine! The two files you referenced in your logs above do not belong to that example:

event - build page: /blog/[slug]
error - ./utils/posts/index.ts

This would indicate you have pages/blog/[slug].ts and utils/posts/index.ts, neither of which exist in the example you linked.

I'll close this issue since it's not actionable without you sharing a reproduction.

@Timer Timer closed this as completed Jan 6, 2021
@dillionmegida
Copy link
Author

I'm sorry about that.

The main issue was the fs module throwing errors until I added next.config.js. I didn't expect to have any more configurations since the template didn't have them too.

Thank you, once again.

@Timer
Copy link
Member

Timer commented Jan 6, 2021

This is caused to an error in your user code. No next.config.js is necessary if you fix the issue in your application. Happy to help you find it if you can share some code!

@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
please add a complete reproduction The issue lacks information for further investigation
Projects
None yet
Development

No branches or pull requests

3 participants