primocms / primo

Primo is a visual CMS with a built-in code editor, Svelte blocks, and static site generator.
https://primocms.org
MIT License
1.92k stars 474 forks source link

Missing catch/finally block in the server-side compilation, beta v46 #378

Closed CMDJojo closed 3 months ago

CMDJojo commented 3 months ago

There seems to be an issue introduced in d90dee80abe05d5da707be88fd74f42978a7d87d. At https://github.com/primocms/primo/blob/ac2999815e11da776d81a32f8957668bc0a478f7/src/compiler/cloud-workers/server-compiler.js#L97 , we have this code:

    try {
      // Override the readFileSync function temporarily
      fs.readFileSync = (path, options) => {
        if (path === modulePath) {
          return vol.readFileSync(path, options)
        }
        return originalFsReadFileSync(path, options)
      }

      const myModule = new Module(modulePath)
      const App = myModule.exports
      const rendered = App.render(component_data)

      payload = {
        head: rendered.head,
        html: rendered.html,
        css: rendered.css.code,
        js: res.dom,
      } 
    }

which is a try without a catch/finally. It fails to build (on Vercel with default settings, Node 18.x I believe). Additionally, when adding an empty catch block, it once again fails to build with this error: Error: [vite]: Rollup failed to resolve import "fetch-blob" from "/vercel/path0/src/compiler/cloud-workers/server-compiler.js" I am not sure of the root cause of the second error. Beta v45 builds just fine (so I rolled back to that)

mateomorris commented 3 months ago

Thanks! Just pushed a hotfix, lemme know if you have any issues with it :)

CMDJojo commented 3 months ago

Thanks! Just synced with your repo, seems to deploy just fine!