首页 > 解决方案 > 在 Angular 中导入模块并从 Scully 获取错误

问题描述

我尝试在我的 Angular 项目中使用 Scully。在 Angular 中,我有一些模块,我必须导入才能使用。但是当我尝试和 Scully 一起奔跑时

npm run scully --scanRoutes --showGuessError

它显示此错误

属于多个模块:

PS C:\Users\sportident\Documents\sportident_web\SiWeb> npm run scully -- --scanRoutes --showGuessError

> si-web@0.0.0 scully C:\Users\sportident\Documents\sportident_web\SiWeb
> scully "--scanRoutes" "--showGuessError"

C:\Users\sportident\Documents\sportident_web\SiWeb C:\Users\sportident\Documents\sportident_web\SiWeb
0.0.93
 ☺   new Angular build imported
 ☺   Started servers in background
Finding all routes in application.
traversing app for routes
Error: Module C:\Users\sportident\Documents\sportident_web\SiWeb\src\app\home\home-routing.module.ts belongs to more than one module: C:\Users\sportident\Documents\sportident_web\SiWeb\src\app\home\home.module.ts, C:\Users\sportident\Documents\sportident_web\SiWeb\src\app\support\support.module.ts
    at Object.exports.getModuleEntryPoint (C:\Users\sportident\Documents\sportident_web\SiWeb\node_modules\guess-parser\dist\guess-parser\index.js:395:15)
    at C:\Users\sportident\Documents\sportident_web\SiWeb\node_modules\guess-parser\dist\guess-parser\index.js:943:40
    at visitTopLevelRoutes (C:\Users\sportident\Documents\sportident_web\SiWeb\node_modules\guess-parser\dist\guess-parser\index.js:910:13)
    at visitNodes (C:\Users\sportident\Documents\sportident_web\SiWeb\node_modules\typescript\lib\typescript.js:18440:30)
    at Object.forEachChild (C:\Users\sportident\Documents\sportident_web\SiWeb\node_modules\typescript\lib\typescript.js:18608:24)
    at NodeObject.forEachChild (C:\Users\sportident\Documents\sportident_web\SiWeb\node_modules\typescript\lib\typescript.js:134791:23)
    at visitTopLevelRoutes (C:\Users\sportident\Documents\sportident_web\SiWeb\node_modules\guess-parser\dist\guess-parser\index.js:913:15)
    at visitNode (C:\Users\sportident\Documents\sportident_web\SiWeb\node_modules\typescript\lib\typescript.js:18431:24)
    at Object.forEachChild (C:\Users\sportident\Documents\sportident_web\SiWeb\node_modules\typescript\lib\typescript.js:18525:21)
    at NodeObject.forEachChild (C:\Users\sportident\Documents\sportident_web\SiWeb\node_modules\typescript\lib\typescript.js:134791:23)

We encountered a problem while reading the routes from your applications source.
This might happen when there are lazy-loaded routes, that are not loaded,
Or when there are paths we can not resolve statically.
Check the routes in your app, rebuild and retry.
(You can inspect the error by passing the --showGuessError flag

When there are extraRoutes in your config, we will still try to render those.



FEHLER: Der Prozess "12072" wurde nicht gefunden.

有人可以请我如何解决这个错误吗?

更新

这是 ng build 的输出

PS C:\Users\sportident\Documents\GitHub\Scully\SiWeb> ng build
Generating ES5 bundles for differential loading...
ES5 bundle generation complete.

chunk {polyfills} polyfills-es2015.js, polyfills-es2015.js.map (polyfills) 281 kB [initial] [rendered]
chunk {center-center-module} center-center-module-es2015.js, center-center-module-es2015.js.map (center-center-module) 10.7 kB  [rendered]        
chunk {center-center-module} center-center-module-es5.js, center-center-module-es5.js.map (center-center-module) 12.1 kB  [rendered]
chunk {blog-blog-module} blog-blog-module-es2015.js, blog-blog-module-es2015.js.map (blog-blog-module) 8.29 kB  [rendered]
chunk {blog-blog-module} blog-blog-module-es5.js, blog-blog-module-es5.js.map (blog-blog-module) 9.91 kB  [rendered]
chunk {other-other-module} other-other-module-es2015.js, other-other-module-es2015.js.map (other-other-module) 8.19 kB  [rendered]
chunk {other-other-module} other-other-module-es5.js, other-other-module-es5.js.map (other-other-module) 9.97 kB  [rendered]
chunk {runtime} runtime-es2015.js, runtime-es2015.js.map (runtime) 9.36 kB [entry] [rendered]
chunk {runtime} runtime-es5.js, runtime-es5.js.map (runtime) 9.36 kB [entry] [rendered]
chunk {main} main-es2015.js, main-es2015.js.map (main) 13.2 kB [initial] [rendered]
chunk {service-service-module} service-service-module-es2015.js, service-service-module-es2015.js.map (service-service-module) 13.1 kB  [rendered]
chunk {service-service-module} service-service-module-es5.js, service-service-module-es5.js.map (service-service-module) 14.5 kB  [rendered]
chunk {support-support-module} support-support-module-es2015.js, support-support-module-es2015.js.map (support-support-module) 39.4 kB  [rendered]
chunk {support-support-module} support-support-module-es5.js, support-support-module-es5.js.map (support-support-module) 38.8 kB  [rendered]
chunk {styles} styles-es2015.js, styles-es2015.js.map (styles) 2.01 MB [initial] [rendered]
chunk {styles} styles-es5.js, styles-es5.js.map (styles) 2.01 MB [initial] [rendered]
chunk {polyfills-es5} polyfills-es5.js, polyfills-es5.js.map (polyfills-es5) 718 kB [initial] [rendered]
chunk {default~home-home-module~support-support-module} default~home-home-module~support-support-module-es2015.js, default~home-home-module~support-support-module-es2015.js.map (default~home-home-module~support-support-module) 948 kB  [rendered]
chunk {default~home-home-module~support-support-module} default~home-home-module~support-support-module-es5.js, default~home-home-module~support-support-module-es5.js.map (default~home-home-module~support-support-module) 1.04 MB  [rendered]

用 ng build --prod 更新

这是 ng build --prod 的输出

PS C:\Users\sportident\Documents\GitHub\Scully> ng build --prod
Generating ES5 bundles for differential loading...
ES5 bundle generation complete.

chunk {1} runtime-es2015.ec43354ddae7200524e5.js (runtime) 2.38 kB [entry] [rendered]
chunk {1} runtime-es5.ec43354ddae7200524e5.js (runtime) 2.38 kB [entry] [rendered]
chunk {3} polyfills-es2015.a06690f5899d30d926de.js (polyfills) 38.1 kB [initial] [rendered]
chunk {7} 7-es2015.44ea9a7d54a26a525593.js () 1.45 kB  [rendered]
chunk {7} 7-es5.44ea9a7d54a26a525593.js () 1.92 kB  [rendered]
chunk {8} 8-es2015.623601e1c9c733cffb63.js () 3.83 kB  [rendered]
chunk {8} 8-es5.623601e1c9c733cffb63.js () 4.28 kB  [rendered]
chunk {9} 9-es2015.779766a928981da4e7e7.js () 2.53 kB  [rendered]
chunk {9} 9-es5.779766a928981da4e7e7.js () 3.08 kB  [rendered]
chunk {10} 10-es2015.f825390b906e1c87c0b5.js () 5.55 kB  [rendered]
chunk {10} 10-es5.f825390b906e1c87c0b5.js () 6 kB  [rendered]
chunk {11} 11-es2015.97f0f0a20b472ec18323.js () 20.3 kB  [rendered]
chunk {11} 11-es5.97f0f0a20b472ec18323.js () 21 kB  [rendered]
chunk {0} 0-es2015.60ea92d6ab2031a0dbec.js () 162 kB  [rendered]
chunk {0} 0-es5.60ea92d6ab2031a0dbec.js () 174 kB  [rendered]
chunk {4} polyfills-es5.5089fdacfadacafffdff.js (polyfills-es5) 131 kB [initial] [rendered]
chunk {2} main-es2015.f2a2cccf2f7b508db936.js (main) 375 kB [initial] [rendered]
chunk {2} main-es5.f2a2cccf2f7b508db936.js (main) 446 kB [initial] [rendered]
chunk {6} 6-es2015.a1a64491bbdb43c56434.js () 673 kB  [rendered]
chunk {6} 6-es5.a1a64491bbdb43c56434.js () 823 kB  [rendered]
chunk {5} styles.2c69555aa35ac891d5f5.css (styles) 151 kB [initial] [rendered]
chunk {scripts} scripts.debb52132dd62a12c627.js (scripts) 145 kB [entry] [rendered]
Date: 2020-07-27T13:08:34.973Z - Hash: 5dbf1fa9b46942db407e - Time: 88346ms

标签: angularimportbuildscullyio

解决方案


这是我们用来在应用程序中查找路由的猜测解析器偶尔会发生的事情。

您可以使用 GuessParserOptions,并设置 excludeFiles,如下图所示

  export const config={
    handle404: 'baseOnly',
    thumbnails: true,
    /**
    * Add all the routes that give this issue in the excludedFiles array
    */
    guessParserOptions: {
      excludedFiles: ['\src\app\home\home-routing.module.ts'],
    },
    routes: {
      '/demo/:id': {
        type: 'extra',
        numberOfPages: 5,
      },
    },
  } as ScullyConfig;

推荐阅读