remix
remix copied to clipboard
[ERROR] Could not resolve "fs/promises"
What version of Remix are you using?
Remix - Cloudflare workers @ latest
Steps to Reproduce
Hello, i'm trying to learn react and remix altogheter, I came across an error, trying to pass a multipart form from frontend to backend via form and action. As i try to import unstable_createMemoryUploadHandler it throws an error related to FS/Promises
17 │ var promises = require('fs/promises');
The package "fs/promises" 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.
Build failed with 1 error:
node_modules/@remix-run/node/upload/fileUploadHandler.js:17:23: ERROR: Could not resolve "fs/promises"
So basically I don't understand if I'm doing something wrong. As I could understand on cloudflare workers I have to rely on their services, and so no storage and so no fileUpload, i'm trying to use the stream to get the file posted with the request to pass it to supabase via service role key.
Any idea what am I missing?
Expected Behavior
Should create a uploaderHandle to pass to
export const action: ActionFunction = async ({
request,
}) => {
const uploadHandler = unstable_createMemoryUploadHandler({
maxFileSize: 500_000,
});
const formData = await unstable_parseMultipartFormData(
request,
uploadHandler
);
const file = formData.get("avatar");
// file is a "File" (https://mdn.io/File) polyfilled for node
// ... etc
Actual Behavior
17 │ var promises = require('fs/promises');
The package "fs/promises" 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.
Build failed with 1 error:
node_modules/@remix-run/node/upload/fileUploadHandler.js:17:23: ERROR: Could not resolve "fs/promises"
Did you solve it?
Did you solve it?
nope. tried a lil' more, as i was trying to figure out how this works, ended up trying setting up a edge function (working on supabase) to overcome the limit.
I couldn't figure out how to go on, and reverted back to next at the moment :)
Same issue. Cloudflare ~Worker~ Pages + Typescript node 17.8.0 npm 8.5.5
Regarding You can use "platform: 'node'" to do that, which will remove this error.
, is this an option I could pass through to esbuild?
You can't use node APIs with Cloudflare. They don't even have a file system.
I had this issue when trying to "re-platform" a default remix app to cloudflare pages in a monorepo created with nx npx create-nx-workspace@latest nx --preset=@nrwl/remix --project=remix-nx
. There were no imports of node APIs in the app code.
I think the issue was that the nx template uses the 'default' remix platform @ v1.0.6, and the imports were from 'remix' rather than '@remix-run/*'. Updating all these references resolved the issue for me:
- ❌
import { Link } from 'remix';
- ✅
import { Link } from "@remix-run/react";
Red herring: I noticed along the way npx remix setup cloudflare
and ran that, but I don't think that resolved the issue.
We are also encountering this issue.
There is an article that suggests to use @esbuild-plugins/node-modules-polyfill
to polyfill fs
, but I was unable to make it work and it still fails with Could not resolve "fs/promises"
.
Anyone who was able to solve this?
I encountered the same issue trying re-platform from the default remix app to Cloudflare-Pages.
In my case the fs-extra
npm package was the culprit. Once the component that used fs-extra was removed, I was able to build the app. This makes sense since Cloudflare (maybe all serverless platforms?) doesn't have a file system.
Works for me with the adjustments I mentioned above @mcmxcdev +1
Thank you Tim, but we already use the new imports rather than the deprecated ones. We also don't use fs-extra
, so no clue where to start.
One way to solve this would be to patch away the line failing the CI run with https://www.npmjs.com/package/patch-package I guess.
It's happening for me as well, but in remix-run/node
Any resolution?

In my case, I was getting this error because I was trying to import from the wrong package,
in entry.client.jsx
I had
import { RemixBrowser } from "@remix-run/node";
which should have been
import { RemixBrowser } from "@remix-run/react";
I assume this could happen with other incorrect imports as well
same issue here. I'm trying to use defer
in cloudflare worker.
For me, the problem was caused by createCookie
from @remix-run/node
. I can't remember why, but I think I read somewhere that this must not be in a route file. So moving this to another file fixed the issue.
Same error here, no idea what the cause is.
Same issu for me, in my case this is due to importing anything (redirect, json) from @remix-run/node
in a yarn PNP monorepo. I didn't find a way around it but to use new Response (...)
I was facing the same issue.
Solution that worked for me : moved createCookie helper to .server file
This should be resolved. Anyone experiencing this should try upgrading to 0.0.0-experimental-2f4891673.
This should be resolved. Anyone experiencing this should try upgrading to 0.0.0-experimental-2f4891673.
~Hi Jacob, I've tried both 0.0.0-experimental-2f4891673 and 1.12.0 and I'm still running into this issue. I'm following the bare bones blog tutorial setup with serverBuildTarget
set to cloudflare-workers
in remix.config.js
and the only @remix-run/node
imports I have are these two in entry.server.tsx
~
import type { EntryContext } from "@remix-run/node";
import { Response } from "@remix-run/node";
Edit: I resolved this by changing the imports from @remix-run/node
to @remix-run/cloudflare
.
TS2305: Module '"@remix-run/cloudflare"' has no exported member 'Response'. Hi @BillBrower-Shopify did you get this error ?
I ended up switching
import { LinksFunction, MetaFunction } from '@remix-run/node'
to
import { LinksFunction, MetaFunction } from '@remix-run/cloudflare'
I'm having the same problem with node v16.13.0. Had to use remix-run/cloudflare
. We definitely need a better solution for this, I lost a long time trying to find better solutions
There is now a polyfill for fs/promises
when building for non-Node platforms, but as others have said, you should be using @remix-run/cloudflare
which doesn't depend on Node built-ins and therefore doesn't need any polyfills.
Note that in the upcoming Remix v2 you'll need to explicitly enable any polyfills via the serverNodeBuiltinsPolyfill option.