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 'fs' #50

Closed
ddresch opened this issue Nov 3, 2022 · 19 comments
Closed

Module not found: Can't resolve 'fs' #50

ddresch opened this issue Nov 3, 2022 · 19 comments

Comments

@ddresch
Copy link

ddresch commented Nov 3, 2022

I'm trying to add outstatic to an existing project. Which is somewhat working. I can access the editor and also the collection creation is running. Currently, I'm struggling with the following issue:

./node_modules/.pnpm/outstatic@0.0.32-rc_3591a07f5f6bd7e95d5c3230e32ada50/node_modules/outstatic/dist/utils/server.js:1:716
Module not found: Can't resolve 'fs'

Import trace for requested module:
./pages/offers/[slug].jsx

It is the copy of the [slug].tsx page of the blog example, so nothing new or special.

I can get rid of the error if I modify my next.config.js like that:

config.resolve.fallback = {
      ...config.resolve.fallback, 
      fs: false
};

But I get now paths or an empty array in the getStaticPaths method:

export async function getStaticPaths() {
  console.log(getDocumentPaths('offers')) // returns empty array
  return {
    paths: getDocumentPaths('offers'),
    fallback: false
  }
}

I'm pretty stuck cause with the empty array it is not dropping an error, but it is ending up constantly in 404 errors of existing pages.

@avitorio
Copy link
Owner

avitorio commented Nov 3, 2022

Hi @ddresch,

Can you inform me your next, react and outstatic versions? Woukd it also be possible to share your [slug] file? Thanks.

@ddresch
Copy link
Author

ddresch commented Nov 3, 2022

Thanks for this quick response!

    "next": "^13.0.0",
    "outstatic": "^0.0.32-rc",
    "react": "^18.0.0",
    "react-dom": "^18.0.0",

The [slug] file is a copy of the blog example.

@avitorio
Copy link
Owner

avitorio commented Nov 3, 2022

Try upgrading outstatic to the latest version. Let me know if it works.

But I've seen this error before, usually it's because 'fs' should only be called on the server side. Somehow it seems the call is being made in the browser... did you change anything in the [slug] file?

@ddresch
Copy link
Author

ddresch commented Nov 3, 2022

Updated to latest version 0.0.33 and copied [slug].tsx again, so no difference. The fs module not found error is gone, but still the getDocumentPaths method returns an empty array and I end up with 404 errors.

@avitorio
Copy link
Owner

avitorio commented Nov 4, 2022

Are there any documents inside your /offers folder?

@avitorio
Copy link
Owner

avitorio commented Nov 4, 2022

As a side note, I just cloned the example project (deploy with vercel), and changed the values to reflect your package.json versions and was unable to replicate the fs not found error.

@avitorio
Copy link
Owner

avitorio commented Nov 8, 2022

Hey @ddresch, I'm closing this due to inactivity. Let me know if you need further help.

@avitorio avitorio closed this as completed Nov 8, 2022
@narendran-kannan
Copy link

I'm also getting the same issue in 0.0.33-rc version

@ddresch
Copy link
Author

ddresch commented Nov 14, 2022

@narendran-kannan did you add outstatic to an already existing project? For me, the 0.0.33-rc closed the issue of not finding the 'fs' module, but it's still not working. But still, the getDocumentPaths method returns an empty array. I checked the code it searches for .mdx files, so I renamed the xyz.md files created by outstatic, but still no luck.

@avitorio
Copy link
Owner

Hi @ddresch and @narendran-kannan, I'd love to be able to reproduce the error to help you find a solution. Would you be able to create an example repository with a minimal install of your current setup to see if I can help? Thanks in advance.

@narendran-kannan
Copy link

I've added outstatic on existing nextjs project,
This is solved when I add below code in next.config file

const nextConfig = {
  reactStrictMode: false,
  webpack: (config) => {
    config.resolve.fallback = { fs: false };
    return config;
  }
}

module.exports = nextConfig

@narendran-kannan
Copy link

I think this is because we've used fs in pages/ folder, not api/?
Correct me If I'm wrong?

@avitorio
Copy link
Owner

But the pages folder only uses fs inside the server side functions... this is why I don't get the error.

What version of NodeJs are you using?

@narendran-kannan
Copy link

18.9.0

@avitorio
Copy link
Owner

Can you create a repo with a simplified version of your project and share it with me?

@narendran-kannan
Copy link

Hey @avitorio as I mentioned below, now it is resolved after adding this in the config, still, need a repo? Let me know, will do.

I've added outstatic on existing nextjs project, This is solved when I add below code in next.config file

const nextConfig = {
  reactStrictMode: false,
  webpack: (config) => {
    config.resolve.fallback = { fs: false };
    return config;
  }
}

module.exports = nextConfig

@avitorio
Copy link
Owner

@narendran-kannan, yes, a repo with the issue would be nice as I'd like to figure out what is the difference in setup that makes some installs work without that config...

@ddresch
Copy link
Author

ddresch commented Nov 15, 2022

I also used this config setting in the first place, which I don't need to use anymore with the updated version 0.33-rc. But still, I get 404 errors in frontend for .mdx pages which are available in outstatic/content/xyz. I compared my site with the blog example up and down and can't find any differences. There needs to be a minor tweak which is missing.

@avitorio
Copy link
Owner

avitorio commented Dec 3, 2022

Hey @ddresch, I noticed our support for .mdx is limited, so this might be why you are getting this error. I've started a new issue for this here #73. Let me know if you'd be interested in helping us out with it. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants