angular(2+)報錯處理之 -- 關於function 、lambda、not supported等

莫莫莫發表於2018-03-06

錯誤資訊

ERROR in Error: Error encountered resolving symbol values statically. Function calls are not supported. Consider replacing the function or lambda with a reference to an exported function (position 194:50 in
 the original .ts file), resolving symbol NgModule in D:/plateform/project-test/node_modules/@angular/platform-browser/node_modules/@angular/core/core.d.ts, resolving symbol BrowserModule in D:/plateform/pr
oject-test/node_modules/@angular/platform-browser/platform-browser.d.ts, resolving symbol BrowserModule in D:/plateform/project-test/node_modules/@angular/platform-browser/platform-browser.d.ts
    at positionalError (D:\plateform\project-test\node_modules\.4.4.3@@angular\compiler\bundles\compiler.umd.js:25266:35)
    at simplifyInContext (D:\plateform\project-test\node_modules\.4.4.3@@angular\compiler\bundles\compiler.umd.js:25109:27)
    at StaticReflector.simplify (D:\plateform\project-test\node_modules\.4.4.3@@angular\compiler\bundles\compiler.umd.js:25123:13)
    at StaticReflector.annotations (D:\plateform\project-test\node_modules\.4.4.3@@angular\compiler\bundles\compiler.umd.js:24553:41)
    at _getNgModuleMetadata (D:\plateform\project-test\node_modules\.4.4.3@@angular\compiler-cli\src\ngtools_impl.js:138:31)
    at _extractLazyRoutesFromStaticModule (D:\plateform\project-test\node_modules\.4.4.3@@angular\compiler-cli\src\ngtools_impl.js:109:26)
    at D:\plateform\project-test\node_modules\.4.4.3@@angular\compiler-cli\src\ngtools_impl.js:129:27
    at Array.reduce (native)
    at _extractLazyRoutesFromStaticModule (D:\plateform\project-test\node_modules\.4.4.3@@angular\compiler-cli\src\ngtools_impl.js:128:10)
    at Object.listLazyRoutesOfModule (D:\plateform\project-test\node_modules\.4.4.3@@angular\compiler-cli\src\ngtools_impl.js:53:22)
    at Function.NgTools_InternalApi_NG_2.listLazyRoutes (D:\plateform\project-test\node_modules\.4.4.3@@angular\compiler-cli\src\ngtools_api.js:91:39)
    at AotPlugin._getLazyRoutesFromNgtools (D:\plateform\project-test\node_modules\.1.7.1@@ngtools\webpack\src\plugin.js:207:44)
    at _donePromise.Promise.resolve.then.then.then.then.then (D:\plateform\project-test\node_modules\.1.7.1@@ngtools\webpack\src\plugin.js:443:24)
    at process._tickCallback (internal/process/next_tick.js:109:7)
複製程式碼

解決辦法

它是typescript的依賴關係問題,在 tsconfig.json檔案中中加

"paths": {
      "@angular/common": ["../node_modules/@angular/common"],
      "@angular/compiler": ["../node_modules/@angular/compiler"],
      "@angular/core": ["../node_modules/@angular/core"],
      "@angular/forms": ["../node_modules/@angular/forms"],
      "@angular/platform-browser": ["../node_modules/@angular/platform-browser"],
      "@angular/platform-browser-dynamic": ["../node_modules/@angular/platform-browser-dynamic"],
      "@angular/router": ["../node_modules/@angular/router"],
      "@angular/http": ["../node_modules/@angular/http"]
    }
複製程式碼

加後形如這樣:

{
  "compilerOptions": {
    "baseUrl": "",
    "declaration": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib": ["es6", "dom"],
    "mapRoot": "./",
    "module": "es6",
    "moduleResolution": "node",
    "outDir": "../dist/out-tsc",
    "sourceMap": true,
    "target": "es5",
    "typeRoots": [
      "../node_modules/@types"
    ],
    "paths": {
      "@angular/common": ["../node_modules/@angular/common"],
      "@angular/compiler": ["../node_modules/@angular/compiler"],
      "@angular/core": ["../node_modules/@angular/core"],
      "@angular/forms": ["../node_modules/@angular/forms"],
      "@angular/platform-browser": ["../node_modules/@angular/platform-browser"],
      "@angular/platform-browser-dynamic": ["../node_modules/@angular/platform-browser-dynamic"],
      "@angular/router": ["../node_modules/@angular/router"],
      "@angular/http": ["../node_modules/@angular/http"]
    }
  }
}

複製程式碼

| 更多報錯處理更新於 github

相關文章