Could not resolve "@cloudflare/pages-plugin-mailchannels"

I'm trying to set up a contact form for a simple Pages site but the instructions on https://blog.cloudflare.com/sending-email-from-workers-with-mailchannels/ just result in a Could not resolve "@cloudflare/pages-plugin-mailchannels" error when I make a new push. npmjs.com seems to indicate that @cloudflare/pages-plugin-mailchannels still exists and has over 1,000 weekly downloads, which suggests it hasn't been renamed, but I have no experience with Cloudflare Workers and I find the distinction between using Workers and using Pages Functions hazy and confusing, so I don't know how to go about testing the "must be manually added as a dependency first" hypothesis with Git-based deploy (the docs just talk about Wrangler) and it being located in functions/_middleware.ts.
The Cloudflare Blog
Send email using Workers with MailChannels
MailChannels has created an email sending service specifically for Cloudflare Workers that removes all the friction associated with sending emails.
5 Replies
kian
kian13mo ago
Have you added the package using a package manager like npm? The Pages build environment will install the dependency if it's in the package.json.
ssokolow
ssokolowOP13mo ago
So I do need to use npm? The docs were very unclear about whether that was specific to the Wrangler-based deployment. Currently, it's deploying from a build folder containing only the functions folder and some HTML generated by a custom Rust-based static site templater.
kian
kian13mo ago
You need to do something to install it The Pages build environment just calls npm install & Wrangler for you
ssokolow
ssokolowOP13mo ago
OK, so I just initialize a dummy NPM project in the root of the Git repo and add the plugin as a dependency? Nope. There's now a package.json and a package-lock.json specifying @cloudflare/pages-plugin-mailchannels as a dependency in the root of the repo and I still get Could not resolve "@cloudflare/pages-plugin-mailchannels".
ssokolow
ssokolowOP13mo ago
This person figured it out. → https://github.com/cloudflare/workers-sdk/issues/1925#issuecomment-1382234959 You need to set your build command to npm install if you want to add this sort of thing to a "no framework" Cloudflare Pages site that's just pulling pre-generated HTML from a Git repo.
GitHub
🐛 BUG: ✘ [ERROR] Could not resolve "@cloudflare/pages-plugin-sentry...
What version of Wrangler are you using? 2.1.6 What operating system are you using? Windows (Git Bash/MINGW) Describe the Bug Summary I am unable to resolve any packages in Cloudflare workers despit...
Want results from more Discord servers?
Add your server