将Angular CLI 1.7.3升级到6.2.2后出现的问题

将Angular CLI 1.7.3升级到6.2.2后出现的问题,angular,webpack,angular6,production-environment,angular-cli-v6,Angular,Webpack,Angular6,Production Environment,Angular Cli V6,我已使用CLI 1.7.3将Angular 5.2.0项目升级为使用CLI 6.2.2的Angular 6.1.7 现在,当我运行ng build-prod时,我得到了以下错误 ERROR in Module build failed (from ./node_modules/mini-css-extract-plugin/dist/loader.js): TypeError: Cannot read property 'replace' of undefined at normaliz

我已使用CLI 1.7.3将Angular 5.2.0项目升级为使用CLI 6.2.2的Angular 6.1.7

现在,当我运行ng build-prod时,我得到了以下错误

ERROR in Module build failed (from ./node_modules/mini-css-extract-plugin/dist/loader.js):
TypeError: Cannot read property 'replace' of undefined
    at normalizeBackSlashDirection (C:\workspace\appView\node_modules\webpack\lib\RequestShortener.js:16:17)
    at new RequestShortener (C:\workspace\appView\node_modules\webpack\lib\RequestShortener.js:26:15)
    at new Compiler (C:\workspace\appView\node_modules\webpack\lib\Compiler.js:189:27)
    at Compiler.createChildCompiler (C:\workspace\appView\node_modules\webpack\lib\Compiler.js:431:25)
    at Compilation.createChildCompiler (C:\workspace\appView\node_modules\webpack\lib\Compilation.js:2429:24)
    at Object.pitch (C:\workspace\appView\node_modules\mini-css-extract-plugin\dist\loader.js:78:43)
如何修复此问题?

发生这种情况是因为您在hTML中使用的TS中声明了一个私有变量

无法读取未定义的属性“replace”

此替换是私有的,因此无法读取HTML文件

更新步骤

安装或更新Angular CLI至版本6

更新Angular CLI很容易,只需使用以下命令从npm安装最新版本:

npm install -g @angular/cli 
npm uninstall -g angular-cli
npm cache clean
ng update
ng update @angular/core
根据您的npm配置,您可能需要添加sudo。 不用说,您需要在系统上安装Node.js 8+和NPM,才能安装和运行Angular CLI 6

将Angular 5 CLI更新为版本6方法2 在安装最新版本之前,您还可以使用以下命令卸载以前的Angular CLI 5版本:

npm install -g @angular/cli 
npm uninstall -g angular-cli
npm cache clean
ng update
ng update @angular/core
接下来全局运行npm install命令:

npm install -g @angular/cli 
升级4 | 5个项目

首先,使用以下命令在本地安装Angular CLI 6,确保您位于项目的根文件夹中:

npm install @angular/cli@latest
ng update @angular/cli
更新配置文件 角度4 | 5和角度6之间存在许多差异,例如 •Angular 6使用Angular.json而不是Angular-cli.json。 •package.json等中依赖项的不同版本

通过从项目的根文件夹运行以下命令,可以自动更新不同的配置文件:

npm install @angular/cli@latest
ng update @angular/cli
发现要更新的包 Angular CLI有一个新的实用程序,允许您自动分析项目的package.json文件,并显示需要更新的依赖项

使用Angular 5项目根文件夹中的终端运行以下命令:

npm install -g @angular/cli 
npm uninstall -g angular-cli
npm cache clean
ng update
ng update @angular/core
这是此命令的输出示例:

将核心包升级到Angular 6 现在需要将核心包/依赖项更新为Angular 6。只需运行以下命令:

npm install -g @angular/cli 
npm uninstall -g angular-cli
npm cache clean
ng update
ng update @angular/core
升级RxJS 您可以使用ng update命令更新RxJS:

ng update rxjs
首先使用以下工具检查已安装Angular CLI的版本和其他依赖项:

ng --version 

尝试更改您的网页,希望这对您有所帮助:

npm remove webpack
然后:

npm install webpack@4.11.1
或者删除节点_模块和package-lock.json更新package.json中的网页包版本
再次运行npm安装。

曾经出现过此问题。问题可能是Angular和CLI版本不兼容。使用npm更新修复了您使用的Web包的mewitch版本?@Andife npm没有运气update@fatemefazli版本4.19.0我在package.json中没有网页包。它是通过@angular devkit/build angular或其他软件包安装的。@Bishan是的,但您可以更改网页包版本。我将通过添加webpack@4.11.1到package.json没有运气。同样的问题再次出现。