Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v3.2.x uses the latest open-next by default, but it's not compatible with open-next@3.0.0 #213

Open
myles2007 opened this issue May 3, 2024 · 3 comments

Comments

@myles2007
Copy link

A few hours ago, I started experiencing build problems unrelated to any recent changes in my project.

After some digging, I realized that open-next published v3.0.0 about 6 hours ago and that cdk-nextjs@v3.2.1 runs npx --yes open-next build with no apparent version specification specification anywhere. As I understand it, this means the latest version on npm will be executed and this is consistent with what I'm seeing (up to and including the build process stating OpenNext v3.0.0 is used).

Specifying a build command like npx --yes open-next@^2 build or installing open-next@2.3.9 as a part of my package dependencies resolves the problem.

There is nothing broken with open-next that I've found, but the default build command in cdk-nextjs@3.2.x is no longer working as of open-next@3.0.0 (at least in some scenarios) unless open-next is declared directly as a project dependency, this is the version that is used to build the target project.

It looks like the beta versions of cdk-nextjs (i.e., v4.0.0-beta.x) won't have this problem because it specifies a version constraint:

const buildCommand = this.props.buildCommand ?? 'npx open-next@^2 build';

I believe the v3.2.x problem can be resolved by adopting the same default command as in v4.0.0-beta.x and would be happy to take a stab at the fix if that is agreeable.

@myles2007
Copy link
Author

In case it's helps anyone to the source of their own issue, I initially encountered this via an error stating that the server-function directory could not be found. Looking at the files on disk, I noticed only server-functions (plural) was present.

With some minor deidentification, the error was:

/path-to/git/project/node_modules/cdk-nextjs-standalone/src/NextjsBuild.ts:149
      if (!silent) throw new Error(Could not find ${standaloneDir} directory.);
                         ^
Error: Could not find /path-to/git/project/project-ui/.open-next/server-function directory.
    at NextjsBuild._getOutputDir (/path-to/git/project/node_modules/cdk-nextjs-standalone/src/NextjsBuild.ts:149:26)
    at new NextjsBuild (/path-to/git/project/node_modules/cdk-nextjs-standalone/src/NextjsBuild.ts:69:33)
    at new Nextjs (/path-to/git/project/node_modules/cdk-nextjs-standalone/src/Nextjs.ts:131:22)
    at new ProjectUiStack (/path-to/git/project/src/stack.project-ui.ts:118:30)
    at new ProjectWebApp (/path-to/git/project/src/construct.projectwebapp.ts:21:21)
    at Object.<anonymous> (/path-to/git/project/src/main.ts:9:1)
    at Module._compile (node:internal/modules/cjs/loader:1256:14)
    at Module.m._compile (/path-to/git/project/node_modules/ts-node/src/index.ts:1618:23)
    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
    at Object.require.extensions.<computed> [as .ts] (/path-to/git/project/node_modules/ts-node/src/index.ts:1621:12)

Subprocess exited with error 1

A quick search showed that at version v3.2.x, cdk-nextjs hardcodes an expectation of the name server-function:

const NEXTJS_BUILD_SERVER_FN_DIR = 'server-function';

This led me to look for changes in open-next and to https://github.com/sst/open-next/blame/ee5794559ede83c0982b1f0a9076d2a0fd9e03a6/packages/open-next/src/build/createServerBundle.ts#L126 and subsequently sst/open-next#402 (OpenNext v3) which made clear open-next had changed recently. This sent me down the path of looking for a way that could happen without a specification change in our project and ultimately to everything outlined above.

@myles2007
Copy link
Author

I also left a message in the Discord group to hopefully help others find a solution if they also experience this issue:
https://discord.com/channels/983865673656705025/1027265626085019769/1236072672572477552

@myles2007 myles2007 changed the title v3.2.x uses the latest open-next by default, but it's not compatible with open-next@v3.0.0 v3.2.x uses the latest open-next by default, but it's not compatible with open-next@3.0.0 May 3, 2024
@khuezy
Copy link
Contributor

khuezy commented May 4, 2024

Thanks for the investigation!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants