标签: angular-cli

Angular CLI:使用业力测试执行时的"意外的令牌导入"

我正在使用带有TypeScript的Angular 2.我使用Angular CLI工具创建了这个项目,并尝试使用命令 - "karma start"运行里面的测试用例 - "app.component.spec.ts".此测试用例由Angular CLI本身生成,并且没有变化.当我运行测试用例时,它会给我以下错误 -

C:\Projects\Angular2\TestProject>karma start
21 08 2016 16:18:34.167:WARN [karma]: No captured browser, open http://localhost:9876/
21 08 2016 16:18:34.178:INFO [karma]: Karma v0.13.22 server started at http://localhost:9876/
21 08 2016 16:18:34.205:INFO [launcher]: Starting browser Chrome
21 08 2016 16:18:36.677:INFO [Chrome 52.0.2743 (Windows 7 0.0.0)]: Connected on socket /#u3qiejjLaOGa5HdGAAAA with id 54026183
Chrome 52.0.2743 (Windows 7 0.0.0) ERROR
  Uncaught SyntaxError: Unexpected token import
  at C:/Projects/Angular2/TestProject/src/app/app.component.spec.ts:5
Run Code Online (Sandbox Code Playgroud)

请问某人如何解决此问题.

app.component.spec.ts -

/* tslint:disable:no-unused-variable */
/// <reference path="../../typings/globals/jasmine/index.d.ts" /> …
Run Code Online (Sandbox Code Playgroud)

typescript karma-runner karma-jasmine angular-cli angular

5
推荐指数
1
解决办法
2914
查看次数

TypeScript错误:找不到命名空间'google'

我有项目angular-cli

〜根〜/ SRC/typings.json

{
  "globalDevDependencies": {
    "angular-protractor": "registry:dt/angular-protractor#1.5.0+20160425143459",
    "jasmine": "registry:dt/jasmine#2.2.0+20160621224255",
    "selenium-webdriver": "registry:dt/selenium-webdriver#2.44.0+20160317120654"
  },
  "globalDependencies": {
    "es6-shim": "registry:dt/es6-shim#0.31.2+20160602141504",
    "google.maps": "registry:dt/google.maps#3.20.0+20160914131659"
  }
}
Run Code Online (Sandbox Code Playgroud)

〜根〜/分型/ index.d.ts

/// <reference path="globals/angular-protractor/index.d.ts" />
/// <reference path="globals/es6-shim/index.d.ts" />
/// <reference path="globals/google.maps/index.d.ts" />
/// <reference path="globals/hammerjs/index.d.ts" />
/// <reference path="globals/jasmine/index.d.ts" />
/// <reference path="globals/selenium-webdriver/index.d.ts" />
Run Code Online (Sandbox Code Playgroud)

〜根〜/ SRC/tsconfig.json

{
  "compilerOptions": {
    "declaration": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib": ["es6", "dom"],
    "mapRoot": "./",
    "module": "es6",
    "moduleResolution": "node",
    "outDir": "../dist/out-tsc",
    "sourceMap": true,
    "target": "es5",
    "typeRoots": [
      "../node_modules/@types",
      "../typings"
    ],
    "files": [ …
Run Code Online (Sandbox Code Playgroud)

typescript angular-cli typescript-typings angular

5
推荐指数
2
解决办法
1万
查看次数

Angular 5 app不会注册服务工作者

我有一个我已经建立的应用程序,SW工作正常.我继续开发而没有注意SW ......现在,在为应用程序充电时,没有更多的SW下载(好像应用程序没有注册SW).

我非常沮丧,因为我不知道如何调试/发现该问题的线索.如何跟踪SW registring进程?

更多背景:

  • 我有:
    • "serviceWorker": true 在.angular-cli.json
    • ServiceWorkerModule.register('/ngsw-worker.js', { enabled: environment.production }) 在我的app.module.ts中
    • 在prod mod中构建我的应用程序并使用http-server(ngsw.json和ngsw-worker.js都可访问)
    • 在开发模式下清理缓存(常规缓存和应用程序/清除存储)
  • 我试过了:
    • 更改app.module导入顺序(我ServiceWorkerModule.register('/ngsw-worker.js', { enabled: environment.production })在BrowserModule和last之后第一次尝试,第二次尝试)
    • 验证那environment.production是true(它)
    • 从头开始生成另一个空的应用程序执行相同的过程(在这种情况下,SW工作......)

我可以检查别的吗?我忘记了什么吗?

如果不是我最后的两个解决方案是:

  • 在空应用中按模块移动模块以解决问题而不理解错误
  • 照明火+萨满歌......

service-worker angular-cli angular

5
推荐指数
1
解决办法
3258
查看次数

在静态解析符号值时遇到错误.调用函数'InputSelected',不支持函数调用

我有一个基于角度2构建的遗留代码.这是我在名为users.input.ts的文件上的代码.它编译成功.但是当我尝试构建时,我得到了编译错误.谁能帮助我做我必须做的事情?

输入select.ts

import { Component, Input, Output, EventEmitter, OnChanges, SimpleChange } from '@angular/core';
import { InputSelectSearchComponent } from '../input-select-search/input-select-search.component';
import { InputBase } from '../../classes/input-base';
import { UIStylekitService } from '../../ui-stylekit.service';

export class InputSelect extends InputBase<string> {
  controlType = 'select';
  options: {value: string, label: string}[] = [];

  constructor(options: {} = {}) {
    super(options);
    this.options = options['options'] || [];
  }
}

@Component({
  selector: 'input-select',
  templateUrl: 'input-select.component.html',
  inputs: ['form','input']
})
export class InputSelectComponent extends InputSelectSearchComponent {

  constructor(
    private __Stylekit: UIStylekitService ) { …
Run Code Online (Sandbox Code Playgroud)

build-error angular-cli angular

5
推荐指数
0
解决办法
104
查看次数

如何将Three.js加载程序导入Angular 6项目

我想使用Three.js(@types/three/index)扩展导入到ng6项目中的类型定义,并使用一组将直接附加到相同“名称空间”的函数。类似于:THREE.myFunction()。我不想声明三any来抑制类型检查和linter,并且我想可以包装一个使用JS类/功能扩展三个的香草JS函数,然后再利用typings.d.ts。

导入装载程序

首先,我想将THREE.js加载程序导入到我的项目中,这通常定义了一个可扩展的vanilla函数THREE。

我正在尝试将BinaryLoaderng服务导入ng服务,但不确定如何以正确的方式进行操作。

到目前为止,我所做的是:

  1. npm install three --save
  2. npm install @types/three --save-dev
  3. import * as THREE from 'three';
  4. 将BinaryLoader添加到新的angular.json scripts数组中

angular.json

        "scripts": [
          "./node_modules/three/examples/js/loaders/BinaryLoader.js"
        ]
Run Code Online (Sandbox Code Playgroud)

到目前为止一切顺利,但是现在我需要创建一个二进制加载器:

import * as THREE from 'three';
// import { BinaryLoader } from 'three';
// import 'three/examples/js/loaders/BinaryLoader';

export class ThreeManagerService {
   const loader = new THREE.BinaryLoader();
   ...
Run Code Online (Sandbox Code Playgroud)

而且我必须找到BinaryLoader以@types/three/index某种方式添加的方法。这样,我应该能够扩展类型定义,以便能够创建新类型THREE.BinaryLoader。可以做这样的事情吗?

我得到的警告是:

警告:./src/app/shared/three-manager.service.ts 24:25-43“在'三个'中找不到导出'BinaryLoader'(导入为'三个') …

three.js angular-cli angular angular6

5
推荐指数
1
解决办法
7949
查看次数

在Angular CLI中从ng-build中排除模块...不起作用

我有一个带有两个应用程序的Angular CLI项目。这两个应用程序是相同的,但是一个应用程序包含构建中的所有文件,另一个则需要排除模块。

Angular CLI版本:1.7.4 Angular版本:5.2.10

我将两个应用程序添加到angular-cli.json文件中,每个应用程序都有一个单独的ts-config文件。

  "apps": [
    {
      "name": "app",   <---- first app
      "root": "src",
      "outDir": "/wwwroot",
      "assets": [
        "assets",
        "favicon.ico"
      ],
      "index": "index.html",
      "main": "main.ts",
      "polyfills": "polyfills.ts",
      "test": "test.ts",
      "tsconfig": "tsconfig.app.json",       <----first TS config
      "testTsconfig": "tsconfig.spec.json",
      "prefix": "app",
      "styles": [
        "styles.scss"
      ],
      "scripts": [],
      "environmentSource": "environments/environment.ts",
      "environments": {
        "dev": "environments/environment.ts",
        "prod": "environments/environment.prod.ts"
      }
    },
    {
      "name": "admin",   <---- second app
      "root": "src",
      "outDir": "/wwwroot",
      "assets": [
        "assets",
        "favicon.ico"
      ],
      "index": "index.html",
      "main": "main.ts",
      "polyfills": "polyfills.ts",
      "test": "test.ts",
      "tsconfig": …
Run Code Online (Sandbox Code Playgroud)

typescript tsconfig angular-cli angular angular5

5
推荐指数
1
解决办法
5418
查看次数

Angular 6.0.1 CLI在执行“ ng lint --type-check”时抛出“ Architect”错误

在Angular和Angular CLI更新到v6之后,我的lint配置每次尝试运行时都会引发以下错误ng lint --type-check:

具有多个目标的Architect命令不能指定替代。'lint'将在以下项目上运行:atlas-fe,atlas-fe-e2e

错误:具有多个目标的Architect命令无法指定替代。'lint'将在以下项目上运行:
    att -fe,atlas-fe-e2e at LintCommand.validate(/ home / nroma / workspace / atlas / proto-fe / node_modules / @ angular / cli / models / architect-command .js:75:23)
    位于/home/nroma/workspace/atlas/proto-fe/node_modules/@angular/cli/models/command-runner.js:274:39     位于/ home / nroma的
    Generator.next()
/workspace/atlas/proto-fe/node_modules/@angular/cli/models/command-runner.js:7:71
    在
    __awaiter(/ home / nroma / workspace / atlas / proto-fe / node_modules / @ angular / cli / models / command-runner.js:3:12)

    在Object的     validateAndRunCommand(/home/nroma/workspace/atlas/proto-fe/node_modules/@angular/cli/models/command-runner.js:273:12)中。(/home/nroma/workspace/atlas/proto-fe/node_modules/@angular/cli/models/command-runner.js:100:26)
    在Generator.next()
    处已实现(/ home / nroma / workspace / atlas /proto-fe/node_modules/@angular/cli/models/command-runner.js:4:58)

我正在使用节点v9.9.0(npm v6.0.1)。

这是我的package.json …

lint angular-cli angular angular6 angular-cli-v6

5
推荐指数
1
解决办法
2682
查看次数

使用多种配置构建应用

是否可以将常见样式与配置特定样式结合在一起?还是要具体说明一下,使用多种配置构建应用?


我有一个应用程序,它根据构建期间使用的配置使用不同的材质主题。这是build应用程序部分的angular.json外观:

"build": {
  "builder": "@angular-devkit/build-angular:browser",
    "options": {
        "outputPath": "dist/my-app",
        "index": "src/index.html",
        "main": "src/main.ts",
        "tsConfig": "src/tsconfig.app.json",
        "scripts": [ ],
        "styles": [
          // These are the common styles
          "src/styles.scss"
        ],
        "assets": [
          "src/assets",
          "src/favicon.ico"
        ]
      },
      "configurations": {
        "theme-one": {
          "styles": [                
            "src/styles/themes/material.theme-one.scss"
          ]
        },
        "theme-two": {
          "styles": [                
            "src/styles/themes/material.theme-two.scss"
          ]
        }
      }
    },
Run Code Online (Sandbox Code Playgroud)

?预期行为:

我想添加/合并styles各个配置中styles指定的以及中的指定build:options。例如,使用以下命令:

ng build --configuration theme-one
Run Code Online (Sandbox Code Playgroud)

上面的命令应包含"src/styles.scss"和"src/styles/themes/material.theme-one.scss"。相同theme-two。

?当前行为:

当前行为是,当我指定配置时,该配置中的 …

angular-cli angular angular6 angular-cli-v6

5
推荐指数
1
解决办法
700
查看次数

升级到Angular 6(从5开始)后,捆绑包大小增加了

我有一个大型的(数百个组件)角(5.2.4)应用程序。我升级了以下组件,并能够构建干净的组件,但是所产生的捆绑包尺寸大于v5:

  • Node.js和Angular CLI已更新
  • Http转换为使用HttpClient
  • rxjs从5转换为6(管道运算符)
  • 将.angular-cli.json转换为新的angular.json
  • 删除/替换了所有已弃用的用法(最小)

由于已知的JS堆引起悲伤,我们使用如下所示的npm脚本进行构建:

node --max_old_space_size=4096 ./node_modules/@angular/cli/bin/ng build --target=production --aot=true --progress=false --env=STAGING
Run Code Online (Sandbox Code Playgroud)

我根据在角度cli中更改的命令将该脚本修改为以下内容:

node --max_old_space_size=4096 ./node_modules/@angular/cli/bin/ng build --prod --aot --progress=false --c=USER
Run Code Online (Sandbox Code Playgroud)

升级之前,我们的主捆绑包大小约为9MB。升级后,约为21MB。任何想法或建议来诊断这一点将不胜感激!

angular-cli angular rxjs6 angular-cli-v6

5
推荐指数
0
解决办法
772
查看次数

在生产中排除资产

我有一些资产(图像,样式)仅在开发(服务时)时需要。这些资产不得包含在生产版本中。在生产中,这些资产由CDN提供。

我需要:

  • ng serve应该提供文件夹./assets-non-build中包含的文件

但:

  • ng build不应在最终版本中插入文件夹./assets-non-build

我在SO上解决了10个类似的问题,在github上解决了5个问题,它们都处理排除文件的问题,但是都没有解决我的情况。

angular-cli angular

5
推荐指数
1
解决办法
1290
查看次数