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

[Bug]: patch_node_fs = True cause next.js standalone build not properly symlink node modules #1033

Open
zfy0701 opened this issue Apr 30, 2023 · 5 comments
Labels
bug Something isn't working repro needed Repro needed to proceed further

Comments

@zfy0701
Copy link

zfy0701 commented Apr 30, 2023

What happened?

when building with next, node module inside standalone will be symlinks, but the files generated by bazel build will have symlink to some absolute path, make the following packing process very hard, make patch_node_fs = False seems works

Version

Development (host) and target OS/architectures:

Output of bazel --version:

Version of the Aspect rules, or other relevant rules from your
WORKSPACE or MODULE.bazel file:

Language(s) and/or frameworks involved:

How to reproduce

No response

Any other information?

No response

@zfy0701 zfy0701 added the bug Something isn't working label Apr 30, 2023
@github-actions github-actions bot added the untriaged Requires traige label Apr 30, 2023
@christian-roggia
Copy link

Do you mind sharing a minimal setup or repository for building with standalone? Thanks!

@alexeagle
Copy link
Member

+1 - there's not enough info in the original post for us to debug this.

How to reproduce
No response

@alexeagle alexeagle added repro needed Repro needed to proceed further and removed untriaged Requires traige labels Aug 3, 2023
@gregjacobs
Copy link
Contributor

Oof, so I think I'm running into this issue as well, except using webpack_devserver instead of Next.js.

It seems that some of the modules are being resolved in the js_run_devserver sandbox (which symlinks to the runfiles' node_modules), but other modules are being resolved to the root node_modules (seemingly transitive dependencies).

node_modules path 1 (root):

<execution_root>/<project>/bazel-out/darwin-opt/bin/node_modules/.aspect_rules_js

node_modules path 2 (runfiles):

<execution_root>/<project>/bazel-out/darwin-opt/bin/path/to/server.sh.runfiles/node_modules/.aspect_rules_js

And sadly, Webpack is resolving modules like 'react' and other 1st-party dependencies in both trees (which immediately causes React hook errors).

I'm trying to create a minimal reproduction that I can send in but having a bit of trouble reproducing in a smaller context. (The project I'm working on is quite large so I'm trying to figure out what exactly triggers the problem)

@zfy0701
Copy link
Author

zfy0701 commented Aug 11, 2023

+1 - there's not enough info in the original post for us to debug this.

How to reproduce
No response

@alexeagle will get back to you with example

@dmeijboom
Copy link

We're having the same issue, error:

INFO: Analyzed target //frontend:frontend (597 packages loaded, 9081 targets configured).
ERROR: /[redacted]/frontend/BUILD:21:14: Error while validating output TreeArtifact File:[[<execution_root>]bazel-out/darwin_arm64-fastbuild/bin]frontend/.next : Failed to resolve relative path standalone/node_modules/next inside TreeArtifact /private/var/tmp/_bazel_[redacted]/b6b87a026ed65b9d149b63a85b35b10b/execroot/_main/bazel-out/darwin_arm64-fastbuild/bin/frontend/.next. The associated file is either missing or is an invalid symlink.
ERROR: /[redacted]/frontend/BUILD:21:14: JsRunBinary frontend/.next failed: not all outputs were created or valid
Target //frontend:frontend failed to build

We using NextJS 14.1.0 with output set to standalone in next.config.js.
Our build file looks like this:

js_run_binary(
    name = "frontend",
    srcs = [
         // sources
    ],
    args = [
        "build",
        "--no-lint",
    ],
    chdir = package_name(),
    out_dirs = [".next"],
    tool = ":next_js_binary",
    visibility = ["//visibility:public"],
)

The issue seems to be that the NextJS project works as intended but it creates .next/standalone which has it's own node_modules folder where the symlinks do not resolve.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working repro needed Repro needed to proceed further
Projects
No open projects
Status: No status
Development

No branches or pull requests

5 participants