问题标签 [angular-cli-v7]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
0 回答
3342 浏览

javascript - 错误:TypeError:无法读取未定义的属性“标志”

我正在为 Angular 进行迁移,这是之前发布的 package.json:

这是发布的新 package.json:

在执行迁移时命令“ng serve”出错:

找不到“AppModule”的 NgModule 元数据中的错误。webpack:编译失败。

甚至在命令“ng build --prod”上发现的错误:

错误:TypeError:无法在 bindChildrenWorker (/home/chaitalimehta) 处读取 checkUnreachable (/home/chaitalimehta/workspace/beyou/public/angular/node_modules/typescript/lib/typescript.js:29004:31) 处未定义的属性“标志” /workspace/beyou/public/angular/node_modules/typescript/lib/typescript.js:27023:17) 在 bindChildren (/home/chaitalimehta/workspace/beyou/public/angular/node_modules/typescript/lib/typescript.js:26979 :17) 在 bindSourceFile (/home/chaitalimehta/workspace/beyou/public/angular/node_modules /typescript/lib/typescript.js:26593:17) 在 Object.bindSourceFile (/home/chaitalimehta/workspace/beyou/public/angular/node_modules/typescript/lib/typescript.js:26534:9) 在 Object.createTypeChecker (/home/chaitalimehta/workspace/beyou/public/angular/node_modules/typescript/lib/typescript.js:56480:20) 的 initializeTypeChecker (/home/chaitalimehta/workspace/beyou/public/angular/ node_modules/typescript/lib/typescript.js:30758:9) 在 getDiagnosticsProducingTypeChecker (/home/chaitalimehta/workspace/beyou/public/angular/node_modules/typescript/lib/typescript.js:85043:93) 在 /home/chaitalimehta/工作区/beyou/public/angular/node_modules/typescript/lib/typescript.js:85171:35 at runWithCancellationToken (/home/chaitalimehta/workspace/beyou/public/angular/node_modules/typescript/lib/typescript.js:85144:24 ) 在 getSemanticDiagnosticsForFileNoCache (/home/chaitalimehta/workspace/beyou/public/angular/node_modules/typescript/lib/typescript.js:85167:20) 在 getAndCacheDiagnostics (/home/chaitalimehta/workspace/beyou/public/angular/node_modules/typescript/lib/typescript.js:85415:26) 在 getSemanticDiagnosticsForFile (/home/chaitalimehta/workspace/beyou/public/angular/node_modules/ typescript/lib/typescript.js:85164:20) 在 getDiagnosticsHelper (/home/chaitalimehta/workspace/beyou/public/angular/node_modules/typescript/lib/typescript.js:85106:24) 在 Object.getSemanticDiagnostics (/home/ chaitalimehta/workspace/beyou/public/angular/node_modules/typescript/lib/typescript.js:85119:20)20) 在 getDiagnosticsHelper (/home/chaitalimehta/workspace/beyou/public/angular/node_modules/typescript/lib/typescript.js:85106:24) 在 Object.getSemanticDiagnostics (/home/chaitalimehta/workspace/beyou/public/angular/ node_modules/typescript/lib/typescript.js:85119:20)20) 在 getDiagnosticsHelper (/home/chaitalimehta/workspace/beyou/public/angular/node_modules/typescript/lib/typescript.js:85106:24) 在 Object.getSemanticDiagnostics (/home/chaitalimehta/workspace/beyou/public/angular/ node_modules/typescript/lib/typescript.js:85119:20)

  1. 尝试清除缓存并重新安装:

    1. rm -rf node_modules dist
    2. npm 缓存清理 --force
    3. // 在 package.json 中添加最新的 typescript
    4. // 删除 package_lock.json
    5. npm 安装
  2. 尝试使用链接从头开始迁移:

    1. https://update.angular.io/
  3. 尝试删除 typescript 然后 tslint 然后 angular-cli

  4. 尝试更改 typescript、tslint、angular-cli 的版本

尝试了很多其他的东西,没有任何解决方案对我有用。

0 投票
1 回答
374 浏览

node.js - 在 mac osx Mojave 上安装 angular cli 7 时出错

我在使用节点版本 10.15.3 和 npm 6.9.0 的 Mac Osx Mojave 10.14.5 上安装 angular@cli 时出错

我还尝试删除并重新安装 node 和 npm,并按照这篇文章Error installation angular/cli on macOS mojave - node-pre-gyp

0 投票
1 回答
1994 浏览

angular-cli-v7 - 如何使用 Angular 8 构建 bundle.js?

任何人都可以帮助我吗?

如何仅使用 angular 8 构建一个 bundle.js?当我执行“npm run build”时,创建了很多 javascript 文件。(例如 main.js/runtime.js/polyfills.js/...)

我希望它们(main.js/runtime.js/polyfills.js/)都可以输出到bundle.js

这是我的packages.json:

我试过了,但是输出了 main.js、polyfills.js、runtime.js 等文件,我希望这些可以连接一个 bundle.js。

0 投票
2 回答
9321 浏览

angular - ng upgrade 命令无法将 cli 从 v7 升级到 v8

用于将 cli 版本从 v7 项目更新到 v8 的 ng upgrade 命令失败。

首先手动尝试升级 cli 也会失败。

您的全局 Angular CLI 版本 (8.0.1) 高于本地版本 (7.3.9)。使用本地 Angular CLI 版本。

包对 " ""@angular/compiler-cli"具有不兼容的对等依赖项。发现不兼容的对等依赖项。看上面。typescript(requires ">=3.1.1 <3.3", would install "3.4.5")

0 投票
2 回答
3444 浏览

angular - “DebugElement”类型上不存在属性“click”

我刚刚开始使用 Karma 和 Jasmine。我被困在无法对组件执行单元测试的地步,我想要触发的功能*ngIf与某些特定值的按钮的条件绑定。

我的.component.ts

头组件.html

x-service.ts

我的.component.spec.ts

从终端运行我的规范文件时,它没有启动它会抛出这样ng test的错误。但是当我更改我的规范文件中的某些内容并保存它时,ng test 会自动运行我的规范文件并显示此错误- 并且 error TS2339: Property 'click' does not exist on type 'DebugElement'TypeError: Cannot read property 'nativeElement' of nullTypeError: Cannot read property 'nativeElement' of null

因此,简而言之,我无法定位 html 文件中的锚标记来触发组件中的回溯功能。我不确定我做错了什么。到目前为止,我已经根据我的搜索和阅读来格式化代码。

任何帮助将不胜感激。谢谢 :)

0 投票
4 回答
9222 浏览

git - 仓库不干净

将 angular 7 更新为 angular 8,我成功更新到angular/cli angular/core使用 command $ ng update @angular/cli@v8 @angular/core@v8。而且我也使用了角度材料,所以我想更新材料然后我用$ ng update @angular/material@v8. 但是在运行命令后我得到了Repository is not clean. Please commit or stash any changes before updating.

所以我在更改 git 之前提交,然后我再次尝试使用相同的命令,然后也得到相同的消息。现在没有要提交或存储的文件。

这是package.json文件的依赖关系: "dependencies": { "@angular/animations": "^8.0.0", "@angular/cdk": "^7.3.7", "@angular/common": "^8.0.0", "@angular/compiler": "^8.0.0", "@angular/core": "^8.0.0", "@angular/forms": "^8.0.0", "@angular/material": "^7.3.7", "@angular/platform-browser": "^8.0.0", "@angular/platform-browser-dynamic": "^8.0.0", "@angular/router": "^8.0.0", "core-js": "^2.5.4", "hammerjs": "^2.0.8", "ngx-loading": "^3.0.1", "rxjs": "6.5.2", "underscore": "^1.9.1", "zone.js": "~0.9.1" }, "devDependencies": { "@angular-devkit/build-angular": "~0.800.0", "@angular/cli": "~8.0.2", "@angular/compiler-cli": "^8.0.0", "@angular/language-service": "^8.0.0", "@types/jasmine": "~2.8.6", "@types/jasminewd2": "~2.0.3", "@types/node": "~8.9.4", "bootstrap-sass": "^3.3.7", "codelyzer": "^5.0.1", "jasmine-core": "~2.99.1", "jasmine-spec-reporter": "~4.2.1", "karma": "~1.7.1", "karma-chrome-launcher": "~2.2.0", "karma-coverage-istanbul-reporter": "~2.0.0", "karma-jasmine": "~1.1.1", "karma-jasmine-html-reporter": "^0.2.2", "karma-scss-preprocessor": "^3.0.0", "protractor": "~5.3.0", "ts-node": "~5.0.1", "tslint": "~5.9.1", "typescript": "~3.4.5" }

这是我收到的信息: D:\test>ng update @angular/material@v8 Repository is not clean. Please commit or stash any changes before updating.

我删除了 node_modules 文件夹并在$ npm install --save. 安装后我再次尝试,然后也收到相同的消息。

有谁知道,如何更新材料?

0 投票
3 回答
33472 浏览

angular - 在 Angular 8 中生成带有组件和路由的模块(使用 angular cli 命令)

我使用 Angular cli 命令ng new my-app创建了新的 Angular 项目

然后,我想在目录中创建名为landing-page 的src/app模块,所以我使用命令ng gm shipping-page --routing=true创建两个文件,即一个模块和一个其路由文件,如下所示:

但是现在,我不想用它的根组件创建模块,并在名为登录页面的单个文件夹中路由,那么我该如何使用单个 cli 命令来做到这一点?

0 投票
1 回答
41 浏览

angular - angular-cli v7开发的pwa应用如何部署在现有网站之上?

我使用 Angular CLI v7 为我现有的网站开发了一个 PWA 应用程序。我想将它部署在我现有网站的顶部。我想要桌面用户的现有网站,但对于移动用户,它应该打开 PWA 应用程序。

如何在没有任何 URL 重定向的情况下实现这一目标?

0 投票
1 回答
721 浏览

angular - 带有外部库的 Angular 项目不能使用 angular-cli 在 AOT 模式下编译

我开始了一个全新的项目,使用 angular-cli 8.1.2 生成。我想为多个微服务(应用程序)提供一个共享库。这个库不应该包含在应用程序文件夹中,它是一个不同的项目,有自己的 git。如果我尝试这样做,应用程序不会在 aot/production 模式下编译,而是在 jit 下工作。

我想要应用程序的 2 个目录中的 2 个项目:

所以我首先用 angular-cli 生成库:

这会在 /test-lib/projects/test-lib 中生成库文件夹和项目

现在我生成(第一个)应用程序:

现在我将 lib 连接到该应用程序:

向 tsconfig.json 添加“路径”:

将导入添加到 app.module.ts:

并将这个标签添加到 app.component.html:

运行“ng serve”现在可以正常工作了。

在文件夹 test-app 中触发“ng build”失败:

此外,它报告:

我尝试在 app.component.ts 中导入组件也失败了(未找到)

难道不应该以简单的方式使用位于外部文件夹中的 angular-cli 创建一个库吗?

0 投票
0 回答
461 浏览

angular - ng test --code-coverage 在升级到 Angular 7 后仅考虑用于单元测试报告的 pollyfills 文件

我已经从 Angular 4 更新到 7。当尝试生成代码覆盖率报告时,代码覆盖率只考虑 polyfills.ts 而没有 .ts 或 .spec.ts 文件,尽管“ng test”命令正确执行所有测试用例并且所有测试用例均通过,“ng test --code-coverage”未生成适当的报告。

在生成的正确报告中如下: 文件 polyfills.ts

实际报告应该在覆盖文件夹中包含所有 .ts 文件报告和 html 报告示例文件
演示脚本 src/business

设置如下:


使固定:

  1. 将以下包添加到 package.json 中的 devDependencies:“@angular-devkit/build-ng-packagr”:“~0.6.3”,b。“ng-packagr”:“^3.0.0-rc.2”

  2. 执行 npm install(或 yarn install)

  3. 在 angular.json 中的项目下为 src 文件夹创建一个新条目,如下所示:

关于这个新条目的注释:

• Angular CLI 要求项目下的所有文件路径都以sourceRoot 路径开头。例如:如果主 test.ts 文件位于 scripts/test(父级),则 test options 中的 main 属性应指向 src/../scripts/test.ts。• 在 angular.json 中的项目属性之外,确保将 defaultProject 属性设置为演示应用程序;如果 src/ 文件夹是 ui-demo-lib,那么 demo/ 文件夹就是 ui-demo。这样现有的构建功能就不会中断。

  1. 在您的 repo 的 test.ts 文件中,删除所有导入并将其替换为以下内容:

完成所有步骤后,如果需要,请尝试将每个额外的导入一一添加。但是,在 Angular 7 的测试环境中需要上面的模块。只有在使用任何区域文件(例如异步测试)时,才应导入其他模块。以下模块不再兼容,与 repo 无关: • zone.js/dist/jasmine-patch

注意:检查以确保指向您的测试的路径是相对于您的测试文件所在的位置。由于 UI_Demo 在 scripts/test.ts 中有它的 test.ts 文件,因此 require.context('../src')

  1. 在 src/tsconfig.spec.json 中,确保 files 属性包括以下内容:test.ts 文件的位置(相对) b. polyfills.ts 文件的位置(相对,通常在 demo 文件夹中找到)
  2. 在 package.json 中:将所有使用 ng-test 的脚本更改为使用 ng-test –project 。湾。替换对 PhantomJS 的任何引用以使用 ChromeHeadless。PhantomJS 不能通过 Angular CLI V7 处理业力。C。前任。ng test --browsers=PhantomJS ------- ng test --project ui-demo-lib --browsers=ChomeHeadless
  3. 可选 - 在 tsconfig.spec.ts 中,将条目“**/ .d.ts”添加到包含属性。
  4. 测试以下命令:ng test --project b. ng test --project --watch=false --browsers=ChromeHeadless --code-coverage c. gulp 内联 d. ng build --aot --output-path=dist (应该默认构建演示)