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

fix: Can't open static-json directory error when using useStatic in devloping #337

Closed
ics-nishihara opened this issue Dec 29, 2020 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@ics-nishihara
Copy link

πŸ› The bug
When I use useStatic, "ENOENT: no such file or directory '.../.nuxt/static-json/foo-bar.json'" error occurs at first access or reload in dev mode.
This error does not cause any other problems, only shows error log.

πŸ› οΈ To reproduce
Steps to reproduce the behavior:

  1. Use useStatic in code, like example.
  2. Run "dev" command
  3. Access the localhost:3000, browser console shows this error at Nuxt SSR.
  4. Reload page, this error is too.

🌈 Expected behaviour
This error doesn't shown at in dev mode.

ℹ️ Additional context
This error fixed by manually adding the "static-json" folder at .nuxt folder.
The problem caused by not making the folder at dev mode, I think.

Thanks.

@ics-nishihara ics-nishihara added the bug Something isn't working label Dec 29, 2020
@dpschen
Copy link

dpschen commented Feb 3, 2021

Based on the additional context I wrote a hacky workaround that seems to remove the warning for now:

  buildModules: [
    // [...]
    function createStaticJsonDirectory() {
      this.nuxt.hook('builder:prepared', () => {
        const fs = require('fs')
        const path = require('path')

        const dir = path.resolve(
          __dirname,
          this.options.buildDir,
          'static-json/'
        )

        if (!fs.existsSync(dir)) {
          fs.mkdirSync(dir)
        }
      })
    },
  ],

@avxkim
Copy link

avxkim commented Feb 7, 2021

This error is shown for me even in a dev environment. @danielroe can you take a look?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants