apache/beam · error · ValueError
File " " is not a valid .js file.
Error message
File "{path}" is not a valid .js file. What it means
The Beam YAML MapToFields transform raises this when a JavaScript UDF is specified via `path` but the file name does not end with '.js'. When neither `expression` nor `callable` is given, the transform loads the UDF from a file, and it only accepts files with a .js extension as a sanity check before reading them via FileSystems.
Solutions
- Rename or point to the file so the path ends with '.js'.
- If the code is TypeScript or needs bundling, compile/transpile it to plain JavaScript first and reference the .js output.
- Alternatively inline the function via the `callable` or `expression` config option instead of `path`.
Example fix
# before config: language: javascript path: my_udf.ts name: udf # after config: language: javascript path: my_udf.js name: udf
Defensive patterns
Strategy: validation
Validate before calling
import os
assert path.endswith('.js'), f'File "{path}" is not a valid .js file.'
assert os.path.isfile(path.replace('gs://', '')) or path.startswith('gs://') Type guard
def is_js_udf_spec(cfg: dict) -> bool:
return isinstance(cfg.get('path'), str) and cfg['path'].endswith('.js') Try / catch
try:
result = expand(cfg)
except ValueError as e:
if 'is not a valid .js file' in str(e):
cfg['path'] = fix_extension(cfg['path'], '.js')
result = expand(cfg)
else:
raise Prevention
- Always use .js extension for JavaScript UDF files
- Transpile TypeScript before referencing it in YAML config
- Prefer inline `expression`/`callable` for short UDFs
When it happens
Trigger: Calling _expand_javascript_mapping_func (via MapToFields with language: javascript) with config {'path': '...', 'name': '...'} where path lacks a .js suffix, e.g. a .ts file, extensionless file, or a directory path.
Common situations: Users point `path` at a TypeScript file, a bundled/minified file with a different extension, a file with wrong casing (.JS handled only if endswith matches exactly — '.JS' fails), or accidentally pass a directory or URL instead of a .js file.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- File " " is not a valid .py file.
- Unknown or unsupported atomic type
- Ambiguous expression type (perhaps missing quoting?)
- Ambiguous expression type (perhaps missing quoting?)
- An invalid input " " was specified in "fields".
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/bc44043d20f17584.
Report an issue: GitHub.
Appendix: source
Thrown at sdks/python/apache_beam/yaml/yaml_mapping.py:276
"quickjs-ng library is not installed.")
if expression:
source_code = f"""
function udf(__row__) {{
with (__row__) {{
return ({expression});
}}
}}
"""
user_entrypoint = 'udf'
elif callable:
source_code = f"var __udf__ = ({callable});"
user_entrypoint = '__udf__'
else:
if not path.endswith('.js'):
raise ValueError(f'File "{path}" is not a valid .js file.')
udf_code = FileSystems.open(path).read().decode()
source_code = udf_code
user_entrypoint = name
source_code += f"""
function __convert_dates__(obj) {{
if (obj && typeof obj === 'object') {{
if (obj.__date__) {{
return new Date(obj.value);
}}
for (var key in obj) {{
if (obj.hasOwnProperty(key)) {{
obj[key] = __convert_dates__(obj[key]);
}}
}}
}}
return obj;
}}View on GitHub (pinned to 12126d8942)