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]: Vite scan files outside of build root #1078

Closed
linke-autra opened this issue May 23, 2023 · 3 comments
Closed

[Bug]: Vite scan files outside of build root #1078

linke-autra opened this issue May 23, 2023 · 3 comments
Labels
bug Something isn't working untriaged Requires traige

Comments

@linke-autra
Copy link

linke-autra commented May 23, 2023

What happened?

I work in a monorepo, we use pnpm as package manager.
Recently I try to use vite in a project, but it's buggy.

My project is under //offline/passport/web, when I build //offline/passport/web:dist directly, everything is fine. but if I build it with others, such as build //... , it seems vite got the whole bazel-out directory as build root, it will scan the whole directory to find nodejs modules, but bazel has lots of ephemeral files here, then vite will fail and quit.

My bazel macro is:

load("@aspect_rules_js//js:defs.bzl", _js_run_binary = "js_run_binary")

def vite(name, srcs, args, **kwargs):
    _bin.vite_binary(
        name = name + "__vite_binary",
        chdir = native.package_name(),
    )
    _js_run_binary(
        name = name,
        mnemonic = kwargs.pop("mnemonic", "Vite"),
        tool = ":%s__vite_binary" % name,
        srcs = srcs,
        args = args,
        chdir = native.package_name(),
        
        tags = ["manual"],
        **kwargs
    )

The target is:

load("@aspect_rules_js//js:defs.bzl", "js_library")
load("//buildtools/rules_web:vite.bzl", "vite")

package(default_visibility = ["//visibility:public"])

npm_link_all_packages(name = "node_modules")

js_library(
    name = "passport_web_srcs",
    srcs = [
        "index.html",
        "vite.config.js",
    ] + glob([
        "src/**/*",
    ]),
    deps = [
        ":node_modules",
    ],
)

vite(
    name = "dist",
    srcs = [
        ":passport_web_lib",
    ],
    args = [
        "build",
    ],
    log_level = "debug",
    out_dirs = ["dist"],
)

Logs here (obviously launch.py is not under //offline/passport and should not be scan by vite):

DEBUG: aspect_rules_js[js_binary]: changing directory to BAZEL_BINDIR (root of Bazel output tree) bazel-out/k8-opt/bin
DEBUG: aspect_rules_js[js_binary]: changing directory to user specified package offline/passport/web
DEBUG: aspect_rules_js[js_binary]: BAZEL_BINDIR bazel-out/k8-opt/bin
DEBUG: aspect_rules_js[js_binary]: BAZEL_BUILD_FILE_PATH offline/passport/web/BUILD
vite build pwd /topgear/.cache/bazel/abcdefg9597ef463226f6e13f5e110cf/execroot/topgear/bazel-out/k8-opt/bin/offline/passport/web
vite v4.3.1 building for production...
transforming...
DEBUG: aspect_rules_js[js_binary]: BAZEL_COMPILATION_MODE opt
DEBUG: aspect_rules_js[js_binary]: BAZEL_PACKAGE offline/passport/web
DEBUG: aspect_rules_js[js_binary]: BAZEL_TARGET_CPU k8
DEBUG: aspect_rules_js[js_binary]: BAZEL_TARGET_NAME dist
DEBUG: aspect_rules_js[js_binary]: BAZEL_WORKSPACE topgear
DEBUG: aspect_rules_js[js_binary]: js_binary FS_PATCH_ROOTS /topgear/.cache/bazel/abcdefg9597ef463226f6e13f5e110cf/execroot/topgear:/topgear/.cache/bazel/abcdefg9597ef463226f6e13f5e110cf/execroot/topgear/bazel-out/k8-opt-exec-2B5CBBC6/bin/offline/passport/web/dist__vite_binary.sh.runfiles
DEBUG: aspect_rules_js[js_binary]: js_binary NODE_PATCHES /topgear/.cache/bazel/abcdefg9597ef463226f6e13f5e110cf/execroot/topgear/bazel-out/k8-opt-exec-2B5CBBC6/bin/offline/passport/web/dist__vite_binary.sh.runfiles/topgear/../aspect_rules_js/js/private/node-patches_legacy/register.js
DEBUG: aspect_rules_js[js_binary]: js_binary NODE_OPTIONS --preserve-symlinks-main
DEBUG: aspect_rules_js[js_binary]: js_binary BINDIR bazel-out/k8-opt-exec-2B5CBBC6/bin
DEBUG: aspect_rules_js[js_binary]: js_binary BUILD_FILE_PATH offline/passport/web/BUILD
DEBUG: aspect_rules_js[js_binary]: js_binary COMPILATION_MODE opt
DEBUG: aspect_rules_js[js_binary]: js_binary NODE_BINARY /topgear/.cache/bazel/abcdefg9597ef463226f6e13f5e110cf/execroot/topgear/bazel-out/k8-opt-exec-2B5CBBC6/bin/offline/passport/web/dist__vite_binary.sh.runfiles/topgear/../nodejs_linux_amd64/bin/nodejs/bin/node
DEBUG: aspect_rules_js[js_binary]: js_binary NODE_WRAPPER /topgear/.cache/bazel/abcdefg9597ef463226f6e13f5e110cf/execroot/topgear/bazel-out/k8-opt-exec-2B5CBBC6/bin/offline/passport/web/dist__vite_binary.sh.runfiles/topgear/offline/passport/web/dist__vite_binary_node_bin/node
DEBUG: aspect_rules_js[js_binary]: js_binary PACKAGE offline/passport/web
DEBUG: aspect_rules_js[js_binary]: js_binary TARGET_CPU k8
DEBUG: aspect_rules_js[js_binary]: js_binary TARGET_NAME dist__vite_binary
DEBUG: aspect_rules_js[js_binary]: js_binary WORKSPACE topgear
DEBUG: aspect_rules_js[js_binary]: js_binary entry point /topgear/.cache/bazel/abcdefg9597ef463226f6e13f5e110cf/execroot/topgear/bazel-out/k8-opt/bin/node_modules/.aspect_rules_js/[email protected]_at_types_node_18.11.18/node_modules/vite/bin/vite.js
INFO: aspect_rules_js[js_binary]: BAZEL_TARGET //offline/passport/web:dist
INFO: aspect_rules_js[js_binary]: js_binary TARGET //offline/passport/web:dist__vite_binary
INFO: aspect_rules_js[js_binary]: js_binary RUNFILES /topgear/.cache/bazel/abcdefg9597ef463226f6e13f5e110cf/execroot/topgear/bazel-out/k8-opt-exec-2B5CBBC6/bin/offline/passport/web/dist__vite_binary.sh.runfiles
INFO: aspect_rules_js[js_binary]: js_binary EXECROOT /topgear/.cache/bazel/abcdefg9597ef463226f6e13f5e110cf/execroot/topgear
INFO: aspect_rules_js[js_binary]: PWD /topgear/.cache/bazel/abcdefg9597ef463226f6e13f5e110cf/execroot/topgear/bazel-out/k8-opt/bin/offline/passport/web
INFO: aspect_rules_js[js_binary]: running /topgear/.cache/bazel/abcdefg9597ef463226f6e13f5e110cf/execroot/topgear/bazel-out/k8-opt-exec-2B5CBBC6/bin/offline/passport/web/dist__vite_binary.sh.runfiles/topgear/offline/passport/web/dist__vite_binary_node_bin/node --preserve-symlinks-main -- /topgear/.cache/bazel/abcdefg9597ef463226f6e13f5e110cf/execroot/topgear/bazel-out/k8-opt/bin/node_modules/.aspect_rules_js/[email protected]_at_types_node_18.11.18/node_modules/vite/bin/vite.js build
DEBUG: aspect_rules_js[js_binary]: overriding process.execPath to node wrapper path /topgear/.cache/bazel/abcdefg9597ef463226f6e13f5e110cf/execroot/topgear/bazel-out/k8-opt-exec-2B5CBBC6/bin/offline/passport/web/dist__vite_binary.sh.runfiles/topgear/offline/passport/web/dist__vite_binary_node_bin/node
DEBUG: aspect_rules_js[js_binary]: node fs patches will be applied with roots: /topgear/.cache/bazel/abcdefg9597ef463226f6e13f5e110cf/execroot/topgear,/topgear/.cache/bazel/abcdefg9597ef463226f6e13f5e110cf/execroot/topgear/bazel-out/k8-opt-exec-2B5CBBC6/bin/offline/passport/web/dist__vite_binary.sh.runfiles
/topgear/.cache/bazel/abcdefg9597ef463226f6e13f5e110cf/external/aspect_rules_js/js/private/node-patches_legacy/fs.js:450
                        throw err;
                        ^

[Error: ENOENT: no such file or directory, stat '/topgear/.cache/bazel/abcdefg9597ef463226f6e13f5e110cf/execroot/topgear/bazel-out/k8-opt/bin/modules/integration/launch.runfiles/topgear/modules/integration/launch.py'] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'stat',
  path: '/topgear/.cache/bazel/abcdefg9597ef463226f6e13f5e110cf/execroot/topgear/bazel-out/k8-opt/bin/modules/integration/launch.runfiles/topgear/modules/integration/launch.py'
}
(16:14:53) INFO: Elapsed time: 626.303s, Critical Path: 290.40s
(16:14:53) INFO: 3931 processes: 2976 disk cache hit, 274 internal, 681 local.
(16:14:53) FAILED: Build did NOT complete successfully
(16:14:53) FAILED: Build did NOT complete successfully

Version

Development (host) and target OS/architectures:
Ubuntu 20.04

Output of bazel --version:
5.1.1

Version of the Aspect rules, or other relevant rules from your
WORKSPACE or MODULE.bazel file:
1.24.0 and 1.26.1 tried both

Language(s) and/or frameworks involved:
JS/JSX, Vite(4.3.1), React 18.2.0

How to reproduce

Use vite in a monorepo which has a lot to build, then run bazel build //...

Any other information?

No response

@linke-autra linke-autra added the bug Something isn't working label May 23, 2023
@github-actions github-actions bot added the untriaged Requires traige label May 23, 2023
@echochamber
Copy link

Not an aspect dev, just a random person who happened on your issue, but have you tried using one of the stricter sandboxing modes when building?

@matthewjh
Copy link

I suspect this has causal overlap with aspect-build/rules_esbuild#58. Vite uses ESBuild, and ESBuild is known to follow symlinks out of the Bazel sandbox.

@linke-autra
Copy link
Author

I migrate from vite. I use webpack/parcel/rspack, all of them works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working untriaged Requires traige
Projects
Archived in project
Development

No branches or pull requests

3 participants