Closed jackcarey closed 1 year ago
I'm pretty sure this is because we are using node:
in the new experimental assets features. We need to avoid importing this if it is not used.
Ah, never mind. The example does use the experimental assets. This feature doesn't yet work outside of Node.js. So you can't use it with the Cloudflare adapter.
@Princesseuh is going to add a warning about using the service, and that's it's only available in Node.js. @Princesseuh personally I think just a simple warning on every dev / build startup that says "Experimental assets support is only available for Node.js runtimes", or something like that.
Ah, never mind. The example does use the experimental assets. This feature doesn't yet work outside of Node.js. So you can't use it with the Cloudflare adapter.
That would make sense, so I took out the experimental
object from the astro config and unused references to the Image
element. However, I get the same error 😕
@matthewp I'm still receiving the error even when the experimental assets aren't being used. My config now looks like this:
import { defineConfig } from 'astro/config';
import tailwind from "@astrojs/tailwind";
import compress from "astro-compress";
import mdx from "@astrojs/mdx";
import sitemap from "@astrojs/sitemap";
import critters from "astro-critters";
import cloudflare from "@astrojs/cloudflare";
// https://astro.build/config
export default defineConfig({
site: 'https://astro-site.pages.dev/',
integrations: [mdx(), tailwind(), sitemap(), critters(), compress()],
output: "server",
adapter: cloudflare({ mode: 'directory' }),
// output: "static",
});
@jackcarey yep, we found a place where that code was being mistakenly imported,when using content collections, and the fix will be released shortly.
@jackcarey yep, we found a place where that code was being mistakenly imported,when using content collections, and the fix will be released shortly.
The update for 6.2.1
fixed the issue - Thank you, I appreciate it :)
Consider trying out the new Compatibility flags: nodejs_compat
to ensure Node imports work
This worked for me. I am using Cloudflare Pages and the Cloudflare Adapter with hybrid
output.
not work above sol
@james2doyle 's solution doesn't work for me either. There are apparently libraries that the experimental assets use that are not handled by the nodejs_compat layer. However, this workaround works for limited use cases: https://github.com/withastro/astro/issues/4109#issuecomment-1653149464
I'm still getting build errors:
node_modules/pg/lib/native/client.js:12:27:
12 │ var EventEmitter = require('events').EventEmitter
I am seeing this same problem in Astro v3.2.3. I am using the AstroWind theme and I am seeing the error even on some plaintext pages for privacy and terms & conditions. Possibly because I am importing a picture for the logo from the Assets directory.
Still getting this in 3.5.3 using the cloudflare adapter.
@pthurmond-vmlyr
I am seeing this same problem in Astro v3.2.3. I am using the AstroWind theme and I am seeing the error even on some plaintext pages for privacy and terms & conditions. Possibly because I am importing a picture for the logo from the Assets directory.
Have you found any working solution? I'm using Astro v4.2.6
with Astrowind v1.0.0-beta.15
and still can't get it work with the Cloudflare adapter.
Ok, so I eventually got it working. I can't remember exactly what I ended up doing. But here is what I am seeing in my code from December.
dependencies: "@astrojs/cloudflare": "^7.7.1", "wrangler": "^3.16.0"
devDependencies: "miniflare": "^3.20231030.0",
import cloudflare from "@astrojs/cloudflare";
// Updates to config output: 'hybrid', adapter: cloudflare()
I think the hybrid part was crucial.
I did upgrade to Astro 4 a few weeks ago. Below are the versions I now have for each package.
"@astrojs/cloudflare": "^9.0.0", "wrangler": "^3.16.0" "miniflare": "^3.20231030.0",
As you can see, I only needed to update the first package.
If you want I can post a full copy of my package.json.
Thanks for sharing @pthurmond-vmlyr
I tried to manually install those libraries, but still getting the Could not resolve "fs"
error. I suspect it could be necessary additional configuration in astro.config.mjs
Ok, I have added my config and my package.json to a Github Gist.
https://gist.github.com/pthurmond-vmlyr/bdbeebefbdebdabaae85a079f310031a
I can add more files to that if you need it.
FYI, I upgraded my site to the latest version of the Cloudflare adapter (v11.x) and my site no longer works with the Cloudflare adapter. This is being tested in a separate branch mind you. Local testing just requires using the npm run build
command.
It does work with my previously stated version of the adapter (9.x).
"@astrojs/cloudflare": "^11.0.1", // Does not work
I don't yet have a solve for it, but I think the cloudflare adapter may need more work.
I do see a related ticket though.
I should add that the 10.x version also fails to work.
iam using 11.0.4 v but still same error "message": "No such module \"node:fs/promises\".\n imported from \"chunks/Layout_vA6ce0ss.mjs\"",
What version of
astro
are you using?2.1.2
Are you using an SSR adapter? If so, which one?
Cloudflare v6.2.0
What package manager are you using?
npm
What operating system are you using?
Windows & CF Workers
What browser are you using?
Chrome
Describe the Bug
output: "static"
, the site builds and can be previewed, except I am obviously missing the Cloudflare functions I'm developing.astro dev
with the CF adapter andoutput: "server"
the site builds and loads correctly in my browser.astro build --verbose
, the build fails both locally and when pushing to CF Pages, with errors about built-in node modules that couldn't be found and warnings about packages being marked withsideEffects: false
.advanced
, to no avail.Here's the info I think is needed:
and the error I am receiving:
Link to Minimal Reproducible Example
https://stackblitz.com/edit/github-5gayx2
Participation