#Cloudflare SSR app not building

15 messages · Page 1 of 1 (latest)

vapid pumice
#

Hi, I'm having an issue building an SSR app for Cloudflare. The site builds fine when not using SSR.

The error when running astro build (there's many more for other packages):```
finalizing server assets

10:58:18 PM [build] Rearranging server assets...
✘ [ERROR] Could not resolve "os"

dist/$server_build/_worker.mjs:3:7:
  3 │ import 'os';
    ╵        ~~~~

The package "os" wasn't found on the file system but is built into node. Are you trying to bundle
for node? You can use "platform: 'node'" to do that, which will remove this error.


My `astro.config.mjs`:```mjs
import { defineConfig } from "astro/config";

// https://astro.build/config
import tailwind from "@astrojs/tailwind";

// https://astro.build/config
import cloudflare from "@astrojs/cloudflare";

// https://astro.build/config
export default defineConfig({
    integrations: [
        tailwind({
            config: {
                applyBaseStyles: false,
            },
        }),
    ],
    output: "server",
    adapter: cloudflare(),
});

My package.json:```json
{
"name": "palera1n-website",
"type": "module",
"version": "1.0.0",
"scripts": {
"dev": "astro dev",
"start": "astro dev",
"build": "astro build",
"preview": "astro preview",
"astro": "astro"
},
"dependencies": {
"@astrojs/cloudflare": "^6.1.1",
"@astrojs/tailwind": "^3.0.0",
"astro": "^2.0.4",
"astro-icon": "^0.8.0",
"astro-seo": "^0.7.0",
"tailwindcss": "^3.0.24"
}
}


❯ node --version
v18.7.0

analog tangle
#

did you try to do what the error asked you to ? Not sure if that'll help though,
unless you specify node adapter, you can't use all node packages.

void gale
#

@vapid pumice did you find a solution to this? I have the same issue and almost similar setup (using node 16.13)

analog tangle
vapid pumice
#

I didn't even see the reply to here, I'll attempt to fix it later if I remember

analog tangle
vapid pumice
void gale
#

I found a fix to my issue, in my case it was svgo causing the issue, which is used by astro-icon. I used pnpm patch to remove remove the svgo call, similar to what's described here: https://github.com/natemoo-re/astro-icon/issues/35#issuecomment-1292183594

GitHub

svgo is a Node.js-only package, thus, it doesn't work in the brand-new environments that Astro SSR supports (e.g. Netlify/Vercel Edge, Deno, Cloudflare workers). Is there any other option t...

vapid pumice
#

yep it is, will try

vapid pumice
#

basically i just used these flags and build command with this patch:

diff --git a/lib/utils.ts b/lib/utils.ts
index daa2485de57847c11196c059fbd4d1942f2bc366..480670fce2c0aea56aea7224b28d806694735b2e 100644
--- a/lib/utils.ts
+++ b/lib/utils.ts
@@ -2,7 +2,6 @@
 import { SPRITESHEET_NAMESPACE } from "./constants";
 import { Props, Optimize } from "./Props";
 import getFromService from "./resolver";
-import { optimize as optimizeSVGNative } from "svgo";
 
 // Adapted from https://github.com/developit/htmlParser
 const splitAttrsTokenizer = /([a-z0-9_\:\-]*)\s*?=\s*?(['"]?)(.*?)\2\s+/gim;
@@ -27,51 +26,7 @@ function optimizeSvg(
   name: string,
   options: Optimize
 ): string {
-  return optimizeSVGNative(contents, {
-    plugins: [
-      "removeDoctype",
-      "removeXMLProcInst",
-      "removeComments",
-      "removeMetadata",
-      "removeXMLNS",
-      "removeEditorsNSData",
-      "cleanupAttrs",
-      "minifyStyles",
-      "convertStyleToAttrs",
-      {
-        name: "cleanupIDs",
-        params: { prefix: `${SPRITESHEET_NAMESPACE}:${name}` },
-      },
-      "removeRasterImages",
-      "removeUselessDefs",
-      "cleanupNumericValues",
-      "cleanupListOfValues",
-      "convertColors",
-      "removeUnknownsAndDefaults",
-      "removeNonInheritableGroupAttrs",
-      "removeUselessStrokeAndFill",
-      "removeViewBox",
-      "cleanupEnableBackground",
-      "removeHiddenElems",
-      "removeEmptyText",
-      "convertShapeToPath",
-      "moveElemsAttrsToGroup",
-      "moveGroupAttrsToElems",
-      "collapseGroups",
-      "convertPathData",
-      "convertTransform",
-      "removeEmptyAttrs",
-      "removeEmptyContainers",
-      "mergePaths",
-      "removeUnusedNS",
-      "sortAttrs",
-      "removeTitle",
-      "removeDesc",
-      "removeDimensions",
-      "removeStyleElement",
-      "removeScriptElement",
-    ],
-  }).data;
+  return contents;
 }
 
 const preprocessCache = new Map();