Javascript NG生成失败模块解析失败:意外令牌-未发生任何更改

Javascript NG生成失败模块解析失败:意外令牌-未发生任何更改,javascript,node.js,angular,typescript,angular8,Javascript,Node.js,Angular,Typescript,Angular8,2天前,我们在使用gitlab ci部署时突然开始出现构建错误。构建脚本中没有任何更改,NPM、NG或Angular的版本也没有更改。同样的编译命令在我们的开发机器上也可以正常工作 _ _ ____ _ ___ / \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _| / △ \ | '_ \ / _` | | | | |/ _` |

2天前,我们在使用gitlab ci部署时突然开始出现构建错误。构建脚本中没有任何更改,NPM、NG或Angular的版本也没有更改。同样的编译命令在我们的开发机器上也可以正常工作

    _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/


Angular CLI: 8.2.1
Node: 10.16.2
OS: linux x64
Angular: 8.1.3
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router, service-worker

Package                            Version
------------------------------------------------------------
@angular-devkit/architect          0.801.3
@angular-devkit/build-angular      0.801.3
@angular-devkit/build-optimizer    0.801.3
@angular-devkit/build-webpack      0.801.3
@angular-devkit/core               8.1.3
@angular-devkit/schematics         8.1.3
@angular/cdk                       8.1.2
@angular/cli                       8.2.1
@angular/fire                      5.2.1
@angular/http                      2.4.10
@angular/material                  8.1.2
@angular/material-moment-adapter   8.1.2
@angular/pwa                       0.801.3
@ngtools/webpack                   8.1.3
@schematics/angular                8.1.3
@schematics/update                 0.802.1
rxjs                               6.5.2
typescript                         3.4.5
webpack                            4.35.2
即使我们尝试重新运行以前成功的构建,它现在也会失败,并出现相同的错误

ERROR in ./src/app/app-routing.module.ts 3:17
Module parse failed: Unexpected token (3:17)
File was processed with these loaders:
 * ./node_modules/@angular-devkit/build-optimizer/src/build-optimizer/webpack-loader.js
 * ./node_modules/@ngtools/webpack/src/index.js
You may need an additional loader to handle the result of these loaders.
| import { Routes } from '@angular/router';
| import { AuthGuard } from './core/guards/auth.guard';
> const ɵ0 = () => import("./modules/auth/auth.module.ngfactory").then(mod => mod.AuthModuleNgFactory), ɵ1 = () => import("./modules/property/property.module.ngfactory").then(mod => mod.PropertyModuleNgFactory), ɵ2 = () => import("./modules/privacy/privacy.module.ngfactory").then(mod => mod.PrivacyModuleNgFactory), ɵ3 = () => import("./modules/homepage/homepage.module.ngfactory").then(mod => mod.HomepageModuleNgFactory), ɵ4 = () => import("./modules/calendar/calendar.module.ngfactory").then(mod => mod.CalendarModuleNgFactory), ɵ5 = () => import("./modules/statistics/statistics.module.ngfactory").then(mod => mod.StatisticsModuleNgFactory);
| const routes = [
|     {
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! gurubnb-frontend-app@0.0.0 build-ci: `ng build --configuration=ci`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the gurubnb-frontend-app@0.0.0 build-ci script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

我不明白为什么以前工作过的东西在版本或代码没有变化的情况下会失败。希望构建仍能工作。

此问题是由webpack和/或acorn中的问题引起的。我发现了其他类似的问题(但不是同样的问题),并决定重新安装acorn,并将网页更新到4.39.2(从4.35.2版),然后我们回到构建中


不知道为什么它突然停止工作,但上述解决了问题

这也发生在我身上。较新版本的webpack(4.39.0)与acorn版本存在一些对等依赖关系。问题是我使用的另一个软件包也有这种依赖关系(使用较旧的版本),因此它是先安装的(出于某种原因(可能与
npm
相关),没有安装webpack依赖关系)

所以我们有两个选择:

1) 安装并降级网页包版本

2) 或者,为了实现这一点,首先卸载安装acorn的依赖项(在我的例子中是
jspdf
),然后重新安装(
npm install
),然后安装删除的依赖项(
npm install jspdf

要检查此依赖性问题是否也发生在您身上,您可以使用
npm ls acorn
查看软件包的生活故事

此图像表示acorn存在问题:

这是一个正确的依赖关系:

这可能是降级的一个好选择,但了解问题发生的原因也是一件好事

希望有帮助

干杯

ERROR in ./src/app/app-routing.module.ts 3:17
Module parse failed: Unexpected token (3:17)
File was processed with these loaders:
 * ./node_modules/@angular-devkit/build-optimizer/src/build-optimizer/webpack-loader.js
 * ./node_modules/@ngtools/webpack/src/index.js
You may need an additional loader to handle the result of these loaders.
| import { Routes } from '@angular/router';
| import { AuthGuard } from './core/guards/auth.guard';
> const ɵ0 = () => import("./modules/auth/auth.module.ngfactory").then(mod => mod.AuthModuleNgFactory), ɵ1 = () => import("./modules/property/property.module.ngfactory").then(mod => mod.PropertyModuleNgFactory), ɵ2 = () => import("./modules/privacy/privacy.module.ngfactory").then(mod => mod.PrivacyModuleNgFactory), ɵ3 = () => import("./modules/homepage/homepage.module.ngfactory").then(mod => mod.HomepageModuleNgFactory), ɵ4 = () => import("./modules/calendar/calendar.module.ngfactory").then(mod => mod.CalendarModuleNgFactory), ɵ5 = () => import("./modules/statistics/statistics.module.ngfactory").then(mod => mod.StatisticsModuleNgFactory);
| const routes = [
|     {
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! gurubnb-frontend-app@0.0.0 build-ci: `ng build --configuration=ci`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the gurubnb-frontend-app@0.0.0 build-ci script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.