Skip to content

Ambient types not found under ng_module #21872

@alexeagle

Description

@alexeagle

Similar to bazelbuild/rules_typescript#31

bazel build :test
INFO: Analysed target //:test (0 packages loaded).
INFO: Found 1 target...
ERROR: /usr/local/google/home/alexeagle/Projects/repro_util_/BUILD:8:1: Compiling Angular templates (ngc) //:test failed (Exit 1)
src/app/search/test.ts(2,35): error TS2307: Cannot find module 'util'.
src/app/search/test.ts(4,21): error TS2307: Cannot find module 'fs'.

Repro:

--- BUILD ---
filegroup(
  name = "node_modules",
  srcs = glob(["node_modules/**/*"]),
  visibility = ["//visibility:public"],
)

load("@angular//:index.bzl", "ng_module")
ng_module(
    name = "test",
    srcs = glob(["src/**/*.ts"]),
    tsconfig = "//:tsconfig.json",
)

--- package.json ---
{
  "name": "repro_util_",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "devDependencies": {
    "@angular/bazel": "5.2.1",
    "@angular/compiler": "5.2.1",
    "@angular/compiler-cli": "5.2.1",
    "@angular/core": "5.2.1",
    "@types/node": "^9.4.0",
    "typescript": "2.4.2"
  }
}

--- tsconfig.json ---
{
  "compilerOptions": {
    "lib": [
      "dom", "es6"
    ],
    "typeRoots": [
      "node_modules/@types"
    ]
  },
  "include": [
    "src/app/search/test.ts"
  ]
}
--- WORKSPACE ---
workspace(name = "ubc_search")

git_repository(
    name = "build_bazel_rules_nodejs",
    remote = "https://github.com/bazelbuild/rules_nodejs.git",
    commit = "c96acafb9df26e44ecc59268a5b3cc9ebafb1d87",
)

load("@build_bazel_rules_nodejs//:defs.bzl", "node_repositories")

node_repositories(package_json = ["//:package.json"])

git_repository(
    name = "build_bazel_rules_typescript",
    remote = "https://github.com/bazelbuild/rules_typescript.git",
    tag = "b94f18bcdbf529615b57bf24de773758c33d85fc",
)

load("@build_bazel_rules_typescript//:setup.bzl", "ts_setup_workspace")

ts_setup_workspace()

load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_setup_workspace")

nodejs_setup_workspace()

local_repository(
    name = "angular",
    path = "node_modules/@angular/bazel",
)

local_repository(
    name = "rxjs",
    path = "node_modules/rxjs/src",
)

git_repository(
    name = "io_bazel_rules_sass",
    remote = "https://github.com/bazelbuild/rules_sass.git",
    tag = "0.0.3",
)

load("@io_bazel_rules_sass//sass:sass.bzl", "sass_repositories")

sass_repositories()

git_repository(
    name = "com_github_bazelbuild_buildtools",
    remote = "https://github.com/bazelbuild/buildtools.git",
    # Note, this commit matches the version of buildifier in angular/ngcontainer
    commit = "b3b620e8bcff18ed3378cd3f35ebeb7016d71f71",
)

http_archive(
    name = "io_bazel_rules_go",
    url = "https://github.com/bazelbuild/rules_go/releases/download/0.9.0/rules_go-0.9.0.tar.gz",
    sha256 = "4d8d6244320dd751590f9100cf39fd7a4b75cd901e1f3ffdfd6f048328883695",
)

load("@io_bazel_rules_go//go:def.bzl", "go_rules_dependencies", "go_register_toolchains")

go_rules_dependencies()


go_register_toolchains()

--- src/app/search/test.ts ---

import { isNullOrUndefined } from 'util';
isNullOrUndefined("hello");
import * as fs from 'fs';
fs.readFile('hello', () => {});

Metadata

Metadata

Assignees

Labels

area: bazelIssues related to the published `@angular/bazel` build rules

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions