repack icon indicating copy to clipboard operation
repack copied to clipboard

Promise may not be fulfilled with 'undefined' when statusCode is not 204

Open milesj opened this issue 2 years ago • 13 comments

Environment

react-native 0.64.2 @callstack/repack 2.5.1

Description

I seem to get this error a lot and I'm not sure why, as there's no other information. It only happens when bundling ios, not android. Here's the full console log.

ℹ [21:46:13.025Z][DevServerProxy] Starting compiler worker { platform: 'ios', port: 64743 }
ℹ [21:46:13.074Z][DevServerProxy] Hermes device connected { deviceId: 2 }
ℹ [21:46:14.087Z][DevServer@ios] Server listening at http://[::]:64743
ℹ [21:46:14.088Z][DevServerProxy] fetching from remote server {
  source: 'http://localhost:64743/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.coinbase.OnboardingMobile'
}
ℹ [21:46:14.094Z][DevServerProxy] fetching from remote server { source: 'http://localhost:64743/api/dashboard/stats?platform=ios' }
ℹ [21:46:14.129Z][webpack-dev-middleware] wait until bundle finished: /index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.coinbase.OnboardingMobile
ℹ [21:46:14.130Z][DevServer@ios] Dashboard client connected { clientId: 'client#0' }
ℹ [21:46:14.132Z][webpack-dev-middleware] wait until bundle finished: /api/dashboard/stats?platform=ios
✖ [21:47:13.971Z][DevServerProxy] Promise may not be fulfilled with 'undefined' when statusCode is not 204 {
  err: {
    type: 'FastifyError',
    message: "Promise may not be fulfilled with 'undefined' when statusCode is not 204",
    stack: "FastifyError: Promise may not be fulfilled with 'undefined' when statusCode is not 204\n" +
      '    at /Users/milesjohnson/Projects/react-native/node_modules/fastify/lib/wrapThenable.js:30:30',
    name: 'FastifyError',
    code: 'FST_ERR_PROMISE_NOT_FULFILLED',
    statusCode: 500
  }
}

Reproducible Demo

milesj avatar Nov 17 '21 21:11 milesj

Does this happen on a fresh project as well?

zamotany avatar Nov 22 '21 13:11 zamotany

No, just ours. I think our project may be too big. With metro, our bundle is 25mb+. When trying to use repack, our bundle is about 50mb, and almost always runs out of memory while trying to bundle.

milesj avatar Nov 22 '21 18:11 milesj

Also happening in one of my project. The bundle size is big for me too.

roshan-lmi avatar Dec 17 '21 21:12 roshan-lmi

Same issue here

geroale avatar Jan 23 '22 16:01 geroale

me too, I refresh the project and this run ok

andreszuluaga-wolox avatar Jan 24 '22 20:01 andreszuluaga-wolox

Any clue on how ti solve this bug.? Any help would be appreciated

mahi8813 avatar Feb 04 '22 06:02 mahi8813

Unfortunately, I don't have any clues. Unless someone provides a reproduction project and I can use, the chances of fixing it are slim.

zamotany avatar Feb 04 '22 09:02 zamotany

This happens to me also on our relatively large project but I don't run out of memory. It seems like a timeout is being hit in the dev server as the build process continues (as seen in the dashboard). When I wait for the build to finish and reload the app everything is "fine". (quotes because I have issues with some modules, will create a separate issue for these)

This case might be simple to fix by removing/extending a timeout?

tom-sherman avatar Mar 02 '22 14:03 tom-sherman

This case might be simple to fix by removing/extending a timeout?

It's worth a shot. I can provide a diff what to edit and alter the timeout and I'd appreciate if someone can apply it and see if the issue still persists.

zamotany avatar Mar 04 '22 11:03 zamotany

Sure, I can try this on our codebase 👍

Just to note tho, we're not currently running repack in production. It's only implemented on a WIP/POC branch right now.

tom-sherman avatar Mar 04 '22 11:03 tom-sherman

Ok I think I found a solution.

I've checked the code and the timeout is set for 5mins so it's not the timeout inside Re.Pack than might be causing the issue, but then I've added short timeout to the request for a bundle: curl "http://localhost:8081/index.bundle?platform=ios" --max-time 10 - the bundle compilation takes around 20+s in TesterApp so curl should terminate the connection due to timeout and it did and I was finally able to see the infamous Promise may not be fulfilled with 'undefined' when statusCode is not 204.

As for the solution: Could someone add return reply; to the end of the forwardRequest (line 234) function inside node_modules/@callstack/repack/dist/server/DevServerProxy.js:

  async forwardRequest(platform, request, reply) {
    if (!this.workers[platform]) {
      await this.runWorker(platform);
    }

    const {
      port
    } = await this.workers[platform];
    const host = request.headers[':authority'] || request.headers.host;
    const url = request.headers[':path'] || request.raw.url;

    if (!url || !host) {
      reply.code(500).send();
    } else {
      const compilerWorkerUrl = `http://localhost:${port}${url}`;
      this.fastify.log.debug({
        msg: 'Fetching from worker',
        url: compilerWorkerUrl,
        method: request.method,
        body: request.body
      });
      reply.from(compilerWorkerUrl);
    }
+   return reply;
  }

zamotany avatar Mar 04 '22 12:03 zamotany

@zamotany This didn't fix it for me unfortunately, i receive the exact same error.

tom-sherman avatar Apr 01 '22 09:04 tom-sherman

Ok I think I found a solution.

I've checked the code and the timeout is set for 5mins so it's not the timeout inside Re.Pack than might be causing the issue, but then I've added short timeout to the request for a bundle: curl "http://localhost:8081/index.bundle?platform=ios" --max-time 10 - the bundle compilation takes around 20+s in TesterApp so curl should terminate the connection due to timeout and it did and I was finally able to see the infamous Promise may not be fulfilled with 'undefined' when statusCode is not 204.

As for the solution: Could someone add return reply; to the end of the forwardRequest (line 234) function inside node_modules/@callstack/repack/dist/server/DevServerProxy.js:

  async forwardRequest(platform, request, reply) {
    if (!this.workers[platform]) {
      await this.runWorker(platform);
    }

    const {
      port
    } = await this.workers[platform];
    const host = request.headers[':authority'] || request.headers.host;
    const url = request.headers[':path'] || request.raw.url;

    if (!url || !host) {
      reply.code(500).send();
    } else {
      const compilerWorkerUrl = `http://localhost:${port}${url}`;
      this.fastify.log.debug({
        msg: 'Fetching from worker',
        url: compilerWorkerUrl,
        method: request.method,
        body: request.body
      });
      reply.from(compilerWorkerUrl);
    }
+   return reply;
  }

returning the reply works for me!

joe06102 avatar Apr 06 '22 11:04 joe06102

This issue has been marked as stale because it has been inactive for 30 days. Please update this issue or it will be automatically closed in 14 days.

github-actions[bot] avatar Feb 07 '24 00:02 github-actions[bot]

This issue has been automatically closed because it has been inactive for more than 14 days. Please reopen if you want to add more context.

github-actions[bot] avatar Feb 21 '24 00:02 github-actions[bot]