标签: angular-cli

Angular2 教程(英雄之旅):找不到模块“./app-routing.module”

我正在阅读此处的 NG2 教程,但遇到了障碍。

\n\n

当我尝试将我的文件导入AppRoutingModule到我的文件中时app.module.ts,出现“ Cannot find module \'./app-routing.module\”错误。我在这里看到了这篇文章以及其他解决方案,但它们似乎都与 相关systemjs,但不相关 webpack。

\n\n

这是我的package.json:

\n\n
{\n  "name": "heroes",\n  "version": "0.0.0",\n  "license": "MIT",\n  "angular-cli": {},\n  "scripts": {\n    "start": "ng serve",\n    "lint": "tslint \\"src/**/*.ts\\"",\n    "test": "ng test",\n    "pree2e": "webdriver-manager update",\n    "e2e": "protractor"\n  },\n  "private": true,\n  "dependencies": {\n    "@angular/common": "2.0.0",\n    "@angular/compiler": "2.0.0",\n    "@angular/core": "2.0.0",\n    "@angular/forms": "2.0.0",\n    "@angular/http": "2.0.0",\n    "@angular/platform-browser": "2.0.0",\n    "@angular/platform-browser-dynamic": "2.0.0",\n    "@angular/router": "3.0.0",\n    "angular2-in-memory-web-api": "0.0.21",\n    "core-js": "^2.4.1",\n    "rxjs": …
Run Code Online (Sandbox Code Playgroud)

angularjs angular-routing angular-cli angular

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

ngserve --proxy-config 与 NTLM 身份验证不起作用

我试图让 Angular cli 的内部网络服务器(我认为 webpack 使用node-http-proxy)与 NTLM 身份验证一起使用,但出现了问题。

我这样设置 webpack 代理:

// in packages.json
...
"scripts": {
    "start": "ng serve --proxy-config proxy.conf.json",
...
Run Code Online (Sandbox Code Playgroud)

proxy.config.json 的内容是:

{
  "/srv": {
    "target": "http://localhost/access_form",
    "logLevel": "debug",
    "auth": "LOGIN:PASS"
  }
}
Run Code Online (Sandbox Code Playgroud)

我试图将 onProxyRes 函数添加到 JSON 选项对象,但这无法启动网络服务器。

有人对这个设置有过运气吗?有什么指点吗?

node-http-proxy webpack webpack-dev-server angular-cli angular

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

Angular - 警告:入口点“@libray-package”包含对“模块/文件”的深度导入

将项目升级到 Angular 9.1 后,CLI 会为各种库发出多个警告,如下所示:

警告:入口点“@azure/msal-angular”包含对“node_modules/msal/lib-commonjs/utils/UrlUtils”的深度导入。这可能不是问题,但可能会导致入口点的编译出现乱序。

警告:入口点“ngx-toastr”包含对“node_modules/@angular/compiler/src/core”的深度导入。这可能不是问题,但可能会导致入口点的编译出现乱序。

我搜索了这个警告并得到了这个 Github 问题:https : //github.com/angular/angular/issues/35615

这使警告消失了。但是这个警告的根本原因是什么以及如何修复它而不是仅仅抑制警告?

typescript angular-cli angular

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

Webpack 生成 SCSS 源映射但不生成 JS

我在https://github.com/franklin626/custom_webpack_undebuggable 上重现了我的问题。

从标准的 Angular 9 CLI 应用程序开始,我需要自定义 webpack 构建,以便我的 SCSS 文件可以导入 JSON 配置。这意味着,在angular.json,从

"serve": {
      "builder": "@angular-devkit/build-angular:dev-server"
Run Code Online (Sandbox Code Playgroud)

到

"serve": {
      "builder": "@angular-builders/custom-webpack:dev-server",
      "options": {
        "customWebpackConfig": {
          "path": "webpack.config.js"
        }
       ...
Run Code Online (Sandbox Code Playgroud)

用webpack.config.js包含下列:

const jsonImporter = require('node-sass-json-importer');

module.exports = {
  mode: 'development',
  module: {
    rules: [
      {
        test: /\.scss$|\.sass$/,
        use: [
          {
            loader: require.resolve('sass-loader'),
            options: {
              implementation: require('node-sass'),
              sassOptions: {
                // bootstrap-sass requires a minimum precision of 8
                precision: 8,
                importer: jsonImporter(),
                outputStyle: 'expanded'
              }
            } …
Run Code Online (Sandbox Code Playgroud)

webpack angular-cli angular angular9

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

无法解析“C:\Portal\\node_modules\string_decoder\node_modules\safe-buffer”中的“buffer”

我正在尝试构建我的 angular 项目并出现以下错误:

Build Command: node --max_old_space_size=8192 node_modules/@angular/cli/bin/ng build --prod
Run Code Online (Sandbox Code Playgroud)

我的 Angular 版本是:@angular/cli: "^8.2.2"。

我尝试重新安装 nodejs 12.13 并删除了 npm-cache 但它仍然不起作用

错误:-

ERROR in ./node_modules/string_decoder/node_modules/safe-buffer/index.js
Module not found: Error: Can't resolve 'buffer' in 
Run Code Online (Sandbox Code Playgroud)

node.js angular-cli angular

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

Angular 9 项目在使用安全空访问和空合并时突然抛出编译错误?

所以这是我遇到的最奇怪的事情,因为这个项目昨天运行得非常好,事实上,我什至在前一天完成工作时“ng serve”仍在运行,一切都很好。

今天来,没有任何变化,尽管我在 3.7.3 全局和 3.8.3 本地运行 angular 项目,但由于 typescript 3.7.2 功能,我无法再编译应用程序。我还在 zone.js 中使用 async/await 收到了一个奇怪的警告,尽管我还没有在我的项目中的任何地方使用 async await —— 不过在过去的 angular 项目中使用 async/await 没有遇到问题。

错误:

WARNING: Zone.js does not support native async/await in ES2017.
Run Code Online (Sandbox Code Playgroud)

和

Module parse failed: Unexpected token (17:38)
>             const address = !!company?.address;
>             if (company?.address) {
Run Code Online (Sandbox Code Playgroud)

它继续指向整个应用程序中的类似内容。现在这个应用程序是在几周前使用 angular cli 9 生成的,我的 tsconfig 没有使用:

        "module": "esnext",
        "moduleResolution": "node",
        "target": "esnext",
        "lib": ["es2018", "dom"]
Run Code Online (Sandbox Code Playgroud)

我很确定这不是我在项目本身中做的任何事情,而是项目是如何编译的,但遗憾的是我不知道在哪里看或我错过了什么,所以任何帮助/建议都非常感谢。

编辑:

删除了本地项目,从 git 复制回来,使用 TS 3.9.5 和相同的问题更新到 angular 10。

typescript zonejs angular-cli angular

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

模块联合共享服务

我正在使用 Angular 11 和 Webpack 5 开展一个新项目。我的工作基于 Manfred Steyer 的Module Federation Plugin Example repo,它使用 Angular CLI。我不知道如何从我的两个应用程序之间共享的本地 Angular 库共享单例服务。

我会尽力解释我的设置.. 真的很抱歉这会持续多久。

简化的文件结构

root
  package.json
  projects/
    shell/
      src/app/
        app.module.ts
        app.component.ts
      webpack.config.ts <-- partial config
    mfe1/
      src/app/
        app.module.ts
        app.component.ts
      webpack.config.ts <-- partial config
    shared/
      src/lib/
        global.service.ts
      package.json <-- package.json for lib

Run Code Online (Sandbox Code Playgroud)

角

两个 app.component.ts 文件是相同的

import {GlobalService} from 'shared';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html'
})
export class AppComponent {
  constructor(shared: SharedService) {}
}
Run Code Online (Sandbox Code Playgroud)

global.service.ts

import { Injectable } from '@angular/core'; …
Run Code Online (Sandbox Code Playgroud)

webpack angular-cli angular nrwl-nx webpack-5

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

Angular CLI 目前需要 npm 版本 6

我正在使用 angular ng new 命令来创建一个应用程序。

ng 新的角度你好世界。

得到以下错误。检测到 npm 版本 7.5.1。Angular CLI 当前需要 npm 版本 6。

请安装兼容版本以继续 ( npm install --global npm@6)。

知道它是什么吗?为什么需要安装 npm@6

angular-cli

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

使用 Angular 11 将 CSS 提取到 JS(不推荐使用的 extractCss)

我们正在使用 Angular 11 应用程序来创建 Web 组件。为此,有必要将所有样式内联捆绑到一个 JS 文件中。在 Angular 11 之前,我们过去常常使用extractCss: falsethenangular.json配置来做到这一点。现在这个选项已被标记为已弃用,我还没有找到任何关于现在应该如何完成的文档。注意。目前extractCss: false仍然有效。

angular-cli

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

从 angular 11.2 升级到 12.2 时出错-styles.css-错误:(0 , _identifier.getUndoPath) 不是函数

正如标题所说,在使用 ng cli 从 angular 11.2 升级到 12.2 后,我在构建我的 angular 应用程序时遇到错误:

styles.css - Error: (0 , _identifier.getUndoPath) is not a function

我没有styles.css 文件(使用styles.scss),也没有看到引用该文件的任何地方。知道可能是什么问题吗?

angular-cli angular

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