nuxt-community / feed-module

Everyone deserves RSS, ATOM and JSON feeds!
MIT License
226 stars 36 forks source link

Nuxt generate fails with version 2.0.0 #85

Closed rclement closed 3 years ago

rclement commented 4 years ago

Hi,

After migrating to version 2.0.0, I can use nuxt generate successfully on my local machine. However, when running CI/CD pipelines on GitHub Actions, the generation always fails with the same error:

> nuxt-ts generate

[fatal] ENOENT: no such file or directory, open '/home/runner/work/***/***/dist/feed/articles/rss.xml'
  at Object.openSync (fs.js:458:3)
  at writeFileSync (fs.js:1279:35)
  at name (node_modules/@nuxtjs/feed/lib/module.js:36:7)
  at Nuxt.callHook (node_modules/hable/src/hable.js:65:11)
  at Generator.generate (node_modules/@nuxt/generator/dist/generator.js:53:5)
  at Object.run (node_modules/@nuxt/cli/dist/cli-generate.js:107:24)
  at NuxtCommand.run (node_modules/@nuxt/cli/dist/cli-index.js:2759:7)
resize:  can't open terminal /dev/tty

   ╭──────────────────────────────────────────────────────────────────────────────────────────╮
   │                                                                                          │
   │   ✖ Nuxt Fatal Error                                                                     │
   │                                                                                          │
   │   Error: ENOENT: no such file or directory, open                                         │
   │   '/home/runner/work/***/***/dist/feed/articles/rss.xml'   │
   │                                                                                          │
   ╰──────────────────────────────────────────────────────────────────────────────────────────╯

It seems related to the execution context of GitHub Actions virtual machines (ubuntu-latest) and of course I cannot reproduce the error anywhere. Reverting to @nuxtjs/feed version 1.1.0 immediately fixes the build.

Any ideas on what's going on? Could it be related to the recent switch to using fs.writeFileSync in @nuxtjs/feed/lib/module.js? (8832f39bf02af7dcacb6115fbd45318e9b633be6)

Let me know if I can provide some more help. Thanks!

Context:

manniL commented 4 years ago

Will investigate! Could you spin up a small example?

Barbapapazes commented 4 years ago

Hello, I have the same here ! Here my repo: https://github.com/Campus-INSA-CVL/campus-website/tree/dev

Just run: npm run build and the error will appear !

image

nuxt: ^2.13.3 @nuxtjs/feed: ^2.0.0

rclement commented 3 years ago

@manniL Sorry for the delay. I could not build a good reproduction use-case for this issue.

However, after some digging I uncovered that since commit 8832f39, the usage of fs-extra.outputFile has been replaced with fs.writeFileSync. However, there is a subtle behavior change: while fs-extra.outputFile was creating all parent directories automatically, fs.writeFileSync does not. Thus all parent directories need to be created if not present already.

And it seems that in some rare weird cases, @nuxtjs/feed tries to output feed files without the output directories in place in "generate mode", causing this issue.

I came up with PR #87 which attempts to fix this issue in the simplest possible way.

@Barbapapazes If you're interested, you can try the fix from PR #87 using npm install github:rclement/feed-module#fix-generate-failure. I tried it on my personal website where the issue originated and it fixed the build.

Barbapapazes commented 3 years ago

Ok, nice ! So I try on my project and it works, no error ! Thank you !

paulrays commented 2 years ago

@manniL Sorry for the delay. I could not build a good reproduction use-case for this issue. ....... I came up with PR #87 which attempts to fix this issue in the simplest possible way.

@Barbapapazes If you're interested, you can try the fix from PR #87 using npm install github:rclement/feed-module#fix-generate-failure. I tried it on my personal website where the issue originated and it fixed the build.

Works like a charm. Any plans of merging it back to master?

rclement commented 2 years ago

@paulrays It has been merged back to master (https://github.com/nuxt-community/feed-module/commit/7c8595d16bdf78bf3f5104a98252e4bd75dc4067) but never been released with a new version.

Alternatively, you can install using npm install github:nuxt-community/feed-module#master