remix: [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"

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 22
  • Comments: 22 (3 by maintainers)

Most upvoted comments

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.

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?

I ended up switching

import { LinksFunction, MetaFunction } from '@remix-run/node'

to

import { LinksFunction, MetaFunction } from '@remix-run/cloudflare'

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 (...)

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.

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 😃

TS2305: Module ‘“@remix-run/cloudflare”’ has no exported member ‘Response’. Hi @BillBrower-Shopify did you get this error ?

Same error here, no idea what the cause is.

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 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.