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

[REF-2086] Avoid "Warning: The path to the Node binary could not be found. #2803

Merged
merged 3 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions .github/workflows/integration_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ jobs:
matrix:
# Show OS combos first in GUI
os: [ubuntu-latest, windows-latest, macos-latest]
node-version: ['16.x']
python-version: ['3.8.18', '3.9.18', '3.10.13', '3.11.5', '3.12.0']
exclude:
- os: windows-latest
Expand All @@ -56,10 +55,6 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- uses: ./.github/actions/setup_build_env
with:
python-version: ${{ matrix.python-version }}
Expand Down Expand Up @@ -104,17 +99,12 @@ jobs:
# Show OS combos first in GUI
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: ['3.10.10', '3.11.4']
node-version: ['16.x']

env:
REFLEX_WEB_WINDOWS_OVERRIDE: '1'
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- uses: ./.github/actions/setup_build_env
with:
python-version: ${{ matrix.python-version }}
Expand Down
2 changes: 1 addition & 1 deletion reflex/constants/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class Node(SimpleNamespace):
# The Node version.
VERSION = "18.17.0"
# The minimum required node version.
MIN_VERSION = "16.8.0"
MIN_VERSION = "18.17.0"

# The node bin path.
BIN_PATH = os.path.join(
Expand Down
20 changes: 15 additions & 5 deletions reflex/utils/prerequisites.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
from reflex.config import Config, get_config
from reflex.utils import console, path_ops, processes

CURRENTLY_INSTALLING_NODE = False


def check_latest_package_version(package_name: str):
"""Check if the latest version of the package is installed.
Expand Down Expand Up @@ -103,8 +105,11 @@ def get_node_version() -> version.Version | None:
Returns:
The version of node.
"""
node_path = path_ops.get_node_path()
if node_path is None:
return None
try:
result = processes.new_process([path_ops.get_node_path(), "-v"], run=True)
result = processes.new_process([node_path, "-v"], run=True)
# The output will be in the form "vX.Y.Z", but version.parse() can handle it
return version.parse(result.stdout) # type: ignore
except (FileNotFoundError, TypeError):
Expand Down Expand Up @@ -606,6 +611,11 @@ def install_node():
console.debug("")
return

# Skip installation if check_node_version() checks out
if check_node_version():
console.debug("Skipping node installation as it is already installed.")
return

path_ops.mkdir(constants.Fnm.DIR)
if not os.path.exists(constants.Fnm.EXE):
download_and_extract_fnm_zip()
Expand All @@ -622,10 +632,6 @@ def install_node():
],
)
else: # All other platforms (Linux, MacOS).
# TODO we can skip installation if check_node_version() checks out
if check_node_version():
console.debug("Skipping node installation as it is already installed.")
return
# Add execute permissions to fnm executable.
os.chmod(constants.Fnm.EXE, stat.S_IXUSR)
# Install node.
Expand Down Expand Up @@ -926,8 +932,12 @@ def initialize_frontend_dependencies():
"""Initialize all the frontend dependencies."""
# validate dependencies before install
validate_frontend_dependencies()
# Avoid warning about Node installation while we're trying to install it.
global CURRENTLY_INSTALLING_NODE
CURRENTLY_INSTALLING_NODE = True
# Install the frontend dependencies.
processes.run_concurrently(install_node, install_bun)
CURRENTLY_INSTALLING_NODE = False
# Set up the web directory.
initialize_web_directory()

Expand Down
11 changes: 9 additions & 2 deletions reflex/utils/processes.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,20 @@ def new_process(args, run: bool = False, show_logs: bool = False, **kwargs):

Returns:
Execute a child program in a new process.

Raises:
Exit: When attempting to run a command with a None value.
"""
node_bin_path = path_ops.get_node_bin_path()
if not node_bin_path:
if not node_bin_path and not prerequisites.CURRENTLY_INSTALLING_NODE:
console.warn(
"The path to the Node binary could not be found. Please ensure that Node is properly "
"installed and added to your system's PATH environment variable."
"installed and added to your system's PATH environment variable or try running "
"`reflex init` again."
)
if None in args:
console.error(f"Invalid command: {args}")
raise typer.Exit(1)
# Add the node bin path to the PATH environment variable.
env = {
**os.environ,
Expand Down
Loading