<#22473 javascript/typescript: imports from built-...
# github-notifications
c
#22473 javascript/typescript: imports from built-in module without `node:` prefix are not inferred Issue created by huonw Describe the bug Node has various builtin modules, e.g.
fs
,
net
. They can be imported either directly, or with a
node:
disambiguating prefix: // direct import import { access } from 'fs'; import { connect } from 'net'; // qualified import import { arch } from 'node:os'; import { basename } from 'node:path'; Pants will give warnings about the first two, without the
node:
prefix, due to dependency inference warnings. This seems undesirable, and will, I imagine, require updating swathes of real-world code to adopt pants. (This is driven by the
_is_node_builtin_module
function. For comparison, the Python BE has a long hard-coded list of stdlib modules in
_STDLIB_MODULES
, to be able to understand that
import <some.stdlib.module>
will be fine.) Reproducer:
Copy code
cd $(mktemp -d)

cat > pants.toml <<EOF
[GLOBAL]
pants_version = "2.29.0.dev0"

backend_packages = [
  "pants.backend.experimental.javascript",
]
EOF

echo 'javascript_sources(name="js")' > BUILD
cat > main.mjs <<EOF
// direct import
import { access } from 'fs';
import { connect } from 'net';
// qualified import
import { arch } from 'node:os';
import { basename } from 'node:path';
EOF

# BUG: "[WARN] Pants cannot infer owners for the following imports in the target //main.mjs:js: ... fs ... net"
pants dependencies main.mjs

# Baseline: this runs fine
node main.mjs
Pants version 2.29.0.dev0 OS macOS Additional info n/a pantsbuild/pants