Skip to content

Commit 37a7db7

Browse files
authored
Fix babel invocation. NFC (#23815)
Babel needs to be able to find the emscripten node modules no matter where the config file or current working directory is.
1 parent 6d49d70 commit 37a7db7

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

tools/building.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,7 @@ def version_split(v):
512512
def transpile(filename):
513513
config = {
514514
'sourceType': 'script',
515+
'presets': ['@babel/preset-env'],
515516
'targets': {}
516517
}
517518
if settings.MIN_CHROME_VERSION != UNSUPPORTED:
@@ -529,8 +530,13 @@ def transpile(filename):
529530
config_file = shared.get_temp_files().get('babel_config.json').name
530531
logger.debug(config_json)
531532
utils.write_file(config_file, config_json)
532-
cmd = shared.get_npm_cmd('babel') + [filename, '-o', outfile, '--presets', '@babel/preset-env', '--config-file', config_file]
533-
check_call(cmd, cwd=path_from_root())
533+
cmd = shared.get_npm_cmd('babel') + [filename, '-o', outfile, '--config-file', config_file]
534+
# Babel needs access to `node_modules` for things like `preset-env`, but the
535+
# location of the config file (and the current working directory) might not be
536+
# in the emscripten tree, so we explicitly set NODE_PATH here.
537+
env = os.environ.copy()
538+
env['NODE_PATH'] = path_from_root('node_modules')
539+
check_call(cmd, env=env)
534540
return outfile
535541

536542

0 commit comments

Comments
 (0)