[Updated] Error when "building" brave from source

I want to build Brave from source and I get struck while running npm run build... (“building”). I am totally new to building apps from source. Please help.

What I did

  1. Cloned the repo https://github.com/brave/brave-browser.git

    git clone https://github.com/brave/brave-browser.git
    
  2. Checked out the tag v1.49.132

    git checkout v1.49.132
    
  3. (Not important) Switched it to a branch building-from-source

    git switch building-from-source
    
  4. Followed this video

    1. npm run init -- --target_os=windows --target_arch=windows

      This one worked out without any errors but the next step produces the error

    2. npm run build Release -- --target_os=windows --target_arch=windows

The Error Message

PS E:\Users\Admin\Code\brave-browser> npm run build Release

> [email protected] build
> cd src/brave && npm run build -- Release


> [email protected] build
> node ./build/commands/scripts/commands.js build Release

touch original files overridden by chromium_src...
touch original vector icon files overridden by brave/vector_icons...
update branding...
Recursing through GRD to find GRDP files...
Done recursing through GRD to find GRDP files.
building native redirect_cc...
-------------------------------------------------------------------------------------------------------------------------------------------------
E:\Users\Admin\Code\brave-browser\src
> gn gen E:\Users\Admin\Code\brave-browser\src\out\redirect_cc --args="import(\"//brave/tools/redirect_cc/args.gni\") use_goma=false goma_dir=\"E:\Users\Admin\Code\brave-browser\src\brave\vendor\depot_tools\.cipd_bin\" real_gomacc=\"E:\Users\Admin\Code\brave-browser\src\brave\vendor\depot_tools\.cipd_bin\gomacc\" is_component_build=true "
Traceback (most recent call last):
  File "E:/Users/Admin/Code/brave-browser/src/build/toolchain/win/setup_toolchain.py", line 314, in <module>
    main()
  File "E:/Users/Admin/Code/brave-browser/src/build/toolchain/win/setup_toolchain.py", line 272, in main
    env = _LoadToolchainEnv(cpu, toolchain_root, win_sdk_path, target_store)
  File "E:/Users/Admin/Code/brave-browser/src/build/toolchain/win/setup_toolchain.py", line 172, in _LoadToolchainEnv
    raise Exception('%s is missing - make sure VC++ tools are installed.' %
Exception: C:\Program Files\Microsoft Visual Studio\2022\Community\VC\vcvarsall.bat is missing - make sure VC++ tools are installed.
ERROR at //build/toolchain/win/toolchain.gni:545:24: Script returned non-zero exit code.
  win_toolchain_data = exec_script("//build/toolchain/win/setup_toolchain.py",
                       ^----------
Current dir: E:/Users/Admin/Code/brave-browser/src/out/redirect_cc/
Command: E:/Users/Admin/Code/brave-browser/src/brave/vendor/depot_tools/bootstrap-2@3_8_10_chromium_26_bin/python3/bin/python3.exe E:/Users/Admin/Code/brave-browser/src/build/toolchain/win/setup_toolchain.py "C:\Program Files/Microsoft Visual Studio/2022/Community" "C:\Program Files (x86)\Wiam Files (x86)\Windows Kits\10" "C:\Windows\System32;C:\Windows\SysWOW64;Arm64Unused" win x86 environment.x86
Returned 1.
See //build/toolchain/win/BUILD.gn:34:3: whence it was called.
  win_toolchains("x86") {
  ^----------------------
See //BUILD.gn:83:1: which caused the file to be included.
group("gn_all") {
^----------------
null
null

It says VC++ tools are missing (Visual C++) but I installed them and I have them.


What do I do?

System Information

  • Edition Windows 10 Pro
  • Version 22H2
  • Installed on ‎20-‎08-‎2022
  • OS build 19045.2728
  • Experience Windows Feature Experience Pack 120.2212.4190.0
  • Processor Intel(R) Core™ i5-2400S CPU @ 2.50GHz 2.50 GHz
  • Installed RAM 8.00 GBSystem type 64-bit operating system, x64-based processor
  • Windows SDK version 10.0.20348.0

Update on this issue

I re-installed the required and did

npm run build Release

and got this error message.

E:\Users\Admin\Code\brave-browser>npm run build Release                                         

> [email protected] build
> cd src/brave && npm run build -- Release


> [email protected] build
> node ./build/commands/scripts/commands.js build Release

touch original files overridden by chromium_src...
touch original vector icon files overridden by brave/vector_icons...
update branding...
Recursing through GRD to find GRDP files...
Done recursing through GRD to find GRDP files.
generating ninja files...
update omaha midl files...
Widevine cdm host verification is disabled
----------------------------------------------------------------------------------------------------------------------------------
E:\Users\Admin\Code\brave-browser\src
> gn gen E:\Users\Admin\Code\brave-browser\src\out\Release --args="sardine_client_id=\"\" sardine_client_secret=\"\" is_asan=falseull_stack_frames_for_profiling=false v8_enable_verify_heap=false disable_fieldtrial_testing_config=true safe_browsing_mode=1 brave_key=\"\" root_extra_deps=[\"//brave\"] is_component_build=false is_universal_binary=false proprietary_codecs=true ffmpeg_branding\" branding_path_component=\"brave\" branding_path_product=\"brave\" enable_nacl=false enable_widevine=true target_cpu=\"x64\" is_build=true is_debug=false dcheck_always_on=false brave_channel=\"\" brave_google_api_key=\"AIzaSyAREPLACEWITHYOUROWNGOOGLEAPIKEY2Qgoogle_api_endpoint=\"https://www.googleapis.com/geolocation/v1/geolocate?key=\" google_default_client_id=\"\" google_default_clie=\"\" brave_infura_project_id=\"\" bitflyer_client_id=\"\" bitflyer_client_secret=\"\" bitflyer_staging_client_id=\"\" bitflyer_stent_secret=\"\" bitflyer_staging_url=\"\" gemini_api_url=\"\" gemini_api_staging_url=\"\" gemini_oauth_url=\"\" gemini_oauth_stagi\" gemini_wallet_client_id=\"\" gemini_wallet_client_secret=\"\" gemini_wallet_staging_client_id=\"\" gemini_wallet_staging_client"\" uphold_client_id=\"\" uphold_client_secret=\"\" uphold_staging_client_id=\"\" uphold_staging_client_secret=\"\" brave_version_\" brave_version_minor=\"49\" brave_version_build=\"132\" chrome_version_string=\"111.0.5563.147\" brave_sync_endpoint=\"\" safebri_endpoint=\"\" brave_variations_server_url=\"\" updater_prod_endpoint=\"\" updater_dev_endpoint=\"\" webcompat_report_api_endpoin://webcompat.brave.com/1/webcompat\" rewards_grant_dev_endpoint=\"\" rewards_grant_staging_endpoint=\"\" rewards_grant_prod_endpoirave_stats_api_key=\"\" brave_stats_updater_url=\"\" enable_hangout_services_extension=true enable_cdm_host_verification=false enaolocales=false skip_signing=true sparkle_dsa_private_key_file=\"\" sparkle_eddsa_private_key=\"\" sparkle_eddsa_public_key=\"\" uslse use_libfuzzer=false enable_updater=true enable_update_notifications=true chrome_pgo_phase=0 cc_wrapper=\"E:\Users\Admin\Code\brave-browser\src\out\redirect_cc\redirect_cc\" enable_brave_page_graph=true enable_brave_page_graph_webapi_probes=true "
ERROR at //brave/components/constants/BUILD.gn:16:3: Assertion failed.
  assert(brave_services_key != "")
  ^-----
See //brave/components/update_client/sources.gni:6:41: which caused the file to be included.
brave_components_update_client_deps = [ "//brave/components/constants" ]
                                        ^-----------------------------
null
null

As this person on reddit said to do

npm run build Static

I did so and got a different error message.

Error message

I am sharing it as an image due to the limit in the length of text.

I asked Google’s Bard on that error and here is its answer:

The error message you are getting is:

ERROR at //brave/components/constants/BUILD.gn:16:3: Assertion failed. assert(brave_services_key != "") ^-----

This means that the brave_services_key variable is empty. This variable is used to set the Brave Services API key.

To fix this error, you need to set the brave_services_key variable to a valid value. You can find the Brave Services API key in the Brave Developer Dashboard.

Once you have set the brave_services_key variable, you should be able to build your project without any errors.

Here are the steps on how to set the brave_services_key variable:

  1. Go to the Brave Developer Dashboard.
  2. Click on the “API Keys” tab.
  3. Click on the “Create Key” button.
  4. Enter a name for your key.
  5. Select the “Brave Services” API.
  6. Click on the “Create” button.
  7. Copy the API key.
  8. Open the brave-browser project directory.
  9. Open the brave/components/constants/BUILD.gn file.
  10. Find the line that says:

brave_services_key = ""

  1. Replace the empty string with the API key you copied in step 7.
  2. Save the file.
  3. Run the npm run build command again.

Once you have completed these steps, you should be able to build your project without any errors.

2 Likes

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.