open-next icon indicating copy to clipboard operation
open-next copied to clipboard

Cannot find module './cjs/react.development.js'

Open conico974 opened this issue 1 year ago • 3 comments

When doing function splitting with only app router component on lambda, this issue can happen. This file is included for every app router route/component, including _app and _document, which are bundled everywhere except on app router only splitted function. (it should not be included btw)

The import is done before the setNodeEnv function call on lambda and so NODE_ENV is undefined and react try to load the dev stuff.

FIX

There is a very easy fix for those running into this set the NODE_ENV env variable to production. This should also be done on sst by default

conico974 avatar Nov 08 '24 12:11 conico974

I'm using SST which calls open-next under the hood but it seems I cannot propagate the environment variable even when using cross-env. Do you have any clue what the issue here might be?

asynchroza avatar Mar 30 '25 13:03 asynchroza

I'm using SST which calls open-next under the hood but it seems I cannot propagate the environment variable even when using cross-env. Do you have any clue what the issue here might be?

whats in your sst.aws.Nextjs and are you using splitted server functions?

sommeeeer avatar Mar 30 '25 14:03 sommeeeer

I'm using SST which calls open-next under the hood but it seems I cannot propagate the environment variable even when using cross-env. Do you have any clue what the issue here might be?

whats in your sst.aws.Nextjs and are you using splitted server functions?

For anybody else who is using SST, after some discussions with the team @sommeeeer and @conico974, I got it running by updating my sst configuration as follows:

// eslint-disable-next-line @typescript-eslint/triple-slash-reference
/// <reference path="./.sst/platform/config.d.ts" />

export default $config({
    app(input) {
        return {
            name: 'pronto',
            removal: input?.stage === 'production' ? 'retain' : 'remove',
            protect: ['production'].includes(input?.stage),
            home: 'aws',
        };
    },
    async run() {
        new sst.aws.Nextjs('Core', {
            environment: {
                // ! @link https://github.com/opennextjs/opennextjs-aws/issues/624
                // TODO: Look into moving to a newer version when this is merged @link https://github.com/opennextjs/opennextjs-aws/pull/800
                NODE_ENV: 'production',
            },
        });
    },
}

asynchroza avatar Mar 30 '25 15:03 asynchroza

Fixed in https://github.com/opennextjs/opennextjs-aws/pull/800

conico974 avatar Sep 21 '25 14:09 conico974