Skip to content
This repository has been archived by the owner on Sep 16, 2021. It is now read-only.

Type resolution fails with bazel managed npm_modules #179

Closed
SirVer opened this issue Mar 28, 2018 · 1 comment
Closed

Type resolution fails with bazel managed npm_modules #179

SirVer opened this issue Mar 28, 2018 · 1 comment
Labels

Comments

@SirVer
Copy link
Contributor

SirVer commented Mar 28, 2018

I have the following build rule:

ts_library(
    name = "client",
    srcs = glob(["control.ts", "xray_viewer.ts"]),
    tsconfig = "//:tsconfig.json",
    node_modules = "@third_party_js//:node_modules", # or "//:node_modules".
)

If I manage my node_modules myself and check it into my repo root, this build rule works. I want to move to bazel managed dependencies though, so I added

yarn_install(
    name = "third_party_js",
    package_json = "//:package.json",
    yarn_lock = "//:yarn.lock",
)

for managing my javascript dependencies and depend on the new @third_party_js//:node_modules rule. This now no longer compiles:

third_party/point_cloud_viewer/xray/client/control.ts(17,24): error TS7016: Could not find a declaration file for module 'three'. '/home/hrapp/.cache/ba
zel/_bazel_hrapp/8de0a1069de8d166c668173ca21c04ae/bazel-sandbox/7039943917462986036/execroot/com_lyft_avsoftware/external/third_party_js/node_modules/th
ree/build/three.js' implicitly has an 'any' type.

I investigated a bit. The problem in the generated tsconfig.file (Gist) is in the path setting and in the typeRoots setting.

According to microsoft/TypeScript#13581 (comment), typeRoots is not used for type resolution for modules, i.e. three in this case. It is searched when a node_modules is found in a top level directory for the files that are compiled, that is why it is found if node_modules is checked into my repository.

A possible and easy fix is to add node_modules/@types to paths - so that the type definitions are found. I proposed a fix for this in a separate PR.

@SirVer
Copy link
Contributor Author

SirVer commented Mar 28, 2018

/cc @pdubroy

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants