Angular AOT构建错误 - 超出最大调用堆栈大小,解析Path中的符号XXX

时间:2017-10-18 14:11:29

标签: angular npm

我创建了一个包含项目中服务的Angular库 我已经在项目中导入了库,并且没有任何问题进行测试。

但是当我试图为我的角度项目进行AOT构建时 出现此错误

Error: Maximum call stack size exceeded, resolving symbol SimpleAuthService in C:/i.rabeea/workspaces/hero/fulfillment_angular/node_modules/zwp-modules/auth/index.d.ts, resolving symbol SimpleAuthService in C:/i.rabeea/workspaces/hero/fulfillment_angular/node_modules/zwp-modules/auth/index.d.ts, ...
at syntaxError (C:\i.rabeea\workspaces\hero\fulfillment_angular\node_modules\@angular\compiler\@angular\compiler.es5.js:1699:2)
at simplifyInContext (C:\i.rabeea\workspaces\hero\fulfillment_angular\node_modules\@angular\compiler\@angular\compiler.es5.js:24949:17)
at StaticReflector.simplify (C:\i.rabeea\workspaces\hero\fulfillment_angular\node_modules\@angular\compiler\@angular\compiler.es5.js:24961:7)
at StaticReflector.annotations (C:\i.rabeea\workspaces\hero\fulfillment_angular\node_modules\@angular\compiler\@angular\compiler.es5.js:24388:38)
at NgModuleResolver.resolve (C:\i.rabeea\workspaces\hero\fulfillment_angular\node_modules\@angular\compiler\@angular\compiler.es5.js:14720:34)
at CompileMetadataResolver.getNgModuleMetadata (C:\i.rabeea\workspaces\hero\fulfillment_angular\node_modules\@angular\compiler\@angular\compiler.es5.js:15372:58)
at addNgModule (C:\i.rabeea\workspaces\hero\fulfillment_angular\node_modules\@angular\compiler\bundles\compiler.umd.js:24268:58)
at C:\i.rabeea\workspaces\hero\fulfillment_angular\node_modules\@angular\compiler\bundles\compiler.umd.js:24279:14
at Array.forEach (<anonymous>)
at _createNgModules (C:\i.rabeea\workspaces\hero\fulfillment_angular\node_modules\@angular\compiler\@angular\compiler.es5.js:24248:8)
at analyzeNgModules (C:\i.rabeea\workspaces\hero\fulfillment_angular\node_modules\@angular\compiler\bundles\compiler.umd.js:24153:14)
at analyzeAndValidateNgModules (C:\i.rabeea\workspaces\hero\fulfillment_angular\node_modules\@angular\compiler\@angular\compiler.es5.js:24133:19)
at AotCompiler.analyzeModulesAsync (C:\i.rabeea\workspaces\hero\fulfillment_angular\node_modules\@angular\compiler\bundles\compiler.umd.js:23797:46)
at CodeGenerator.codegen (C:\i.rabeea\workspaces\hero\fulfillment_angular\packages\compiler-cli\src\codegen.ts:41:10)
at C:\i.rabeea\workspaces\hero\fulfillment_angular\node_modules\src\main.ts:19:84
at Object.main (C:\i.rabeea\workspaces\hero\fulfillment_angular\node_modules\@angular\tools\@angular\tsc-wrapped\src\main.ts:136:12)
at Object.runInternal (C:\i.rabeea\workspaces\hero\fulfillment_angular\node_modules\src\main.ts:24:10)
at C:\i.rabeea\workspaces\hero\fulfillment_angular\node_modules\src\plugin.ts:64:21
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
at Function.Module.runMain (module.js:667:11)
at startup (bootstrap_node.js:187:16)
at bootstrap_node.js:607:3

这是解决问题的脚本 &#34;建立:AOT:PROD:基地&#34;

当我删除此标记&#34; cross-env BUILD_AOT = 1&#34;从脚本开始工作,但是在生产中运行app时我需要这个。

"scripts": {
"build:aot:prod:base": "npm run clean:dist && npm run clean:aot && cross-env BUILD_AOT=1 npm run webpack -- --config config/webpack.prod.js  --progress --profile --bail",
"build:aot:dev-conf": "cross-env CONF_FILE=./config.dev.json npm run build:aot:prod:base",
"build:aot:prod-conf": "cross-env CONF_FILE=./config.prod.json npm run build:aot:prod:base",
"build:aot:prod": "cross-env CONF_FILE=./config.dev.json npm run build:aot:prod:base",
"build:aot": "npm run build:aot:prod",
"build:dev": "npm run clean:dist && npm run webpack -- --config config/webpack.dev.js --progress --profile",
"build:docker": "npm run build:prod && docker build -t angular2-webpack-start:latest .",
"build:prod": "npm run clean:dist && npm run webpack -- --config config/webpack.prod.js  --progress --profile --bail",
"build": "npm run build:dev",
"ci:aot": "npm run lint && npm run test && npm run build:aot && npm run e2e",
"ci:jit": "npm run lint && npm run test && npm run build:prod && npm run e2e",
"ci:nobuild": "npm run lint && npm test && npm run e2e",
"ci:testall": "npm run lint && npm run test && npm run build:prod && npm run e2e && npm run build:aot && npm run e2e",
"ci:travis": "npm run lint && npm run test && npm run build:aot && npm run e2e:travis",
"ci": "npm run ci:testall",
"clean:all": "npm run rimraf -- doc coverage dist compiled dll",
"clean:dll": "npm run rimraf -- dll",
"clean:aot": "npm run rimraf -- compiled",
"clean:dist": "npm run rimraf -- dist",
"clean:install": "npm set progress=false && npm install",
"clean": "npm cache clean --force && npm run rimraf -- node_modules doc coverage dist compiled dll",
"deploy:prod": "npm run clean:all && npm prune --force && npm install && npm version patch",
"deploy:test": "npm run clean:all && npm prune --force && npm install && npm test && npm run build:aot:prod",
"docker": "docker",
"docs": "npm run typedoc -- --options typedoc.json --exclude '**/*.spec.ts' ./src/",
"docs:compodoc": "compodoc -p tsconfig.json",
"docs:compodoc:serve": "compodoc -p tsconfig.json -s",
"docs:compodoc:serve:watch": "compodoc -p tsconfig.json -s -w",
"e2e:live": "npm-run-all -p -r server:prod:ci protractor:live",
"e2e:travis": "npm-run-all -p -r server:prod:ci protractor:delay",
"e2e": "npm-run-all -p -r server:prod:ci protractor",
"github-deploy:dev": "npm run webpack -- --config config/webpack.github-deploy.js --progress --profile --env.githubDev",
"github-deploy:prod": "npm run webpack -- --config config/webpack.github-deploy.js --progress --profile --env.githubProd",
"github-deploy": "npm run github-deploy:dev",
"lint": "npm run tslint \"src/**/*.ts\"",
"node": "node",
"postinstall": "npm run webdriver:update",
"postversion": "git push && git push --tags",
"preclean:install": "npm run clean",
"preversion": "npm test",
"protractor": "protractor",
"protractor:delay": "sleep 3 && npm run protractor",
"protractor:live": "protractor --elementExplorer",
"rimraf": "rimraf",
"server:dev:hmr": "npm run server:dev -- --hotOnly",
"server:dev:hmr:browser": "npm run server:dev:browser -- --hotOnly",
"server:dev": "npm run rimraf -- .awcache && npm run webpack-dev-server -- --config config/webpack.dev.js --progress --profile --watch --content-base src/",
"server:dev:browser": "npm run server:dev -- --open",
"server:prod": "http-server dist -c-1 --cors",
"server:prod:ci": "http-server dist -p 3001 -c-1 --cors",
"server": "npm run server:dev",
"start:hmr": "npm run server:dev:hmr",
"start:hmr:browser": "npm run server:dev:hmr:browser",
"start": "npm run server:dev",
"test": "npm run lint && karma start",
"tslint": "tslint",
"typedoc": "typedoc",
"version": "npm run build:aot:prod",
"watch:dev:hmr": "npm run watch:dev -- --hot",
"watch:dev": "npm run build:dev -- --watch",
"watch:prod": "npm run build:prod -- --watch",
"watch:aot:prod": "npm run build:aot:prod -- --watch",
"watch:test": "npm run test -- --auto-watch --no-single-run",
"watch": "npm run watch:dev",
"webdriver-manager": "webdriver-manager",
"webdriver:start": "npm run webdriver-manager start",
"webdriver:update": "webdriver-manager update",
"webpack-dev-server": "node --max_old_space_size=4096 node_modules/webpack-dev-server/bin/webpack-dev-server.js",
"webpack": "node --max_old_space_size=4096 node_modules/webpack/bin/webpack.js"
}

1 个答案:

答案 0 :(得分:1)

我会搜索您的代码以获取对SimpleAuthService的引用。

感谢Igor关于循环依赖关系的问题,例如:小心如何使用桶,例如fileA导入SimpleAuthService,它还导入一个index.ts,它导入SimpleAuthService或其他循环关系。在这种情况下,一种方法可能是明确导入某些项目而不是通过桶。

注意:在AOT期间,您通常会遇到更多编译问题,这是一件好事!即在开发周期中使用AOT编译时的良好做法,以确保它已准备好进行PROD构建。 AOT抓住了合法的问题。