You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Sep 16, 2021. It is now read-only.
When building a ts_library in worker mode, the build will fail if the rule has transitive @npm dependencies and their @types targets are not included as a direct dependency.
$ bazel build --strategy=TypeScriptCompile=worker //test:ts_default_library
INFO: Analysed target //test:ts_default_library (0 packages loaded, 2 targets configured).
INFO: Found 1 target...
ERROR: /Users/xiaoyi/Projects/depot/test/BUILD.bazel:3:1: Compiling TypeScript (devmode) //test:ts_default_library failed (Exit 1)
error TS2688: Cannot find type definition file for 'classnames'.
error TS2688: Cannot find type definition file for 'connect'.
error TS2688: Cannot find type definition file for 'dom4'.
error TS2688: Cannot find type definition file for 'events'.
error TS2688: Cannot find type definition file for 'express'.
error TS2688: Cannot find type definition file for 'express-serve-static-core'.
error TS2688: Cannot find type definition file for 'faker'.
error TS2688: Cannot find type definition file for 'google-libphonenumber'.
error TS2688: Cannot find type definition file for 'google-protobuf'.
error TS2688: Cannot find type definition file for 'history'.
error TS2688: Cannot find type definition file for 'hoist-non-react-statics'.
error TS2688: Cannot find type definition file for 'http-proxy'.
error TS2688: Cannot find type definition file for 'http-proxy-middleware'.
error TS2688: Cannot find type definition file for 'jest'.
error TS2688: Cannot find type definition file for 'jwt-decode'.
error TS2688: Cannot find type definition file for 'loglevel'.
error TS2688: Cannot find type definition file for 'long'.
error TS2688: Cannot find type definition file for 'memory-fs'.
error TS2688: Cannot find type definition file for 'mime'.
error TS2688: Cannot find type definition file for 'node'.
error TS2688: Cannot find type definition file for 'object-path'.
error TS2688: Cannot find type definition file for 'pluralize'.
error TS2688: Cannot find type definition file for 'prop-types'.
error TS2688: Cannot find type definition file for 'qiniu-js'.
error TS2688: Cannot find type definition file for 'range-parser'.
error TS2688: Cannot find type definition file for 'react'.
error TS2688: Cannot find type definition file for 'react-dom'.
error TS2688: Cannot find type definition file for 'react-router'.
error TS2688: Cannot find type definition file for 'react-router-dom'.
error TS2688: Cannot find type definition file for 'recompose'.
error TS2688: Cannot find type definition file for 'serve-static'.
error TS2688: Cannot find type definition file for 'tapable'.
error TS2688: Cannot find type definition file for 'uglify-js'.
error TS2688: Cannot find type definition file for 'underscore'.
error TS2688: Cannot find type definition file for 'webpack'.
error TS2688: Cannot find type definition file for 'webpack-dev-middleware'.
error TS2688: Cannot find type definition file for 'webpack-dev-server'.
error TS2688: Cannot find type definition file for 'webpack-env'.
error TS2688: Cannot find type definition file for 'yup'.
The problem is that TypeScript reads the @types directory and discovers all these typings files, because it has an aggressive and non-hermetic automatic discovery of ambient (non-imported) typings.
Under Bazel we only allow reads of files that are declared as inputs to an action, ensuring that the typescript compilation could be run remotely for example.
Our typical solution for this is to change tsconfig.json to disable that ambient typings discovery using "compilerOptions": { "types": [] }. Then in a compilation unit which actually requires some ambient typings we use the ///<reference types="foo"/> syntax to explicitly "import" that typing.
Some ideas:
we should improve the error message to indicate the possibility that typescript discovered a typing that isn't in the deps, and suggest what to do
figure out why TypeScript automatic discovery picks up these typings - I know we implemented a readDirectory in the compilerHost, maybe we can fix there
we could have Bazel always add the empty types option to your tsconfig (ideally we should do this only if the user didn't explicitly declare it, which means it should happen in tsconfig.ts where we read the options and set defaults)
To make worker mode work with TypeScript ambient type discovery, always
zero out the compilerOptions#types in the generated tsconfig - users
should provide these as deps[] instead.
Fixesbazelbuild/rules_typescript#449
🐞 bug report
Affected Rule
The issue is caused by the rule:
ts_library
Is this a regression?
Not sure.
Description
When building a
ts_library
in worker mode, the build will fail if the rule has transitive @npm dependencies and their @types targets are not included as a direct dependency.🔬 Minimal Reproduction
tsconfig.json
index.tsx
BUILD.bazel
🔥 Exception or Error
🌍 Your Environment
Operating System:
Output of
bazel version
:Rules version (SHA):
Anything else relevant?
The text was updated successfully, but these errors were encountered: