在Angular Universal版本

时间:2019-05-10 10:50:36

标签: angular-universal

我的Angular 7 portfolio-app with ngUniversal已按照official cli documentation进行了设置。我为传入数据和一些常用功能设置了接口。

"scripts": {
    "ng": "ng",
    "start": "npm run serve:ssr",
    "build": "npm run build:ssr",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "compile:server": "webpack --config webpack.server.config.js --progress --colors",
    "serve:ssr": "node dist/server",
    "build:ssr": "npm run build:client-and-server-bundles && npm run compile:server",
    "build:client-and-server-bundles": "ng build --prod && ng run my-portfolio:server:production"
}

接口说明和文件夹结构:

Interface description and folder structure

使用界面的组件:

Component using the interface


问题

在运行 ng运行my-portfolio:server:production 后,通用构建失败,并显示错误,如屏幕快照所示。

原因:未在任何模块中注册的接口和常用功能。它们只是导入到组件中。

Error while running ng run my-portfolio:server:production

完整错误:

  

PS C:\ Acclaris \ Practice \ AngularPractice \ my-portfolio> npm运行构建

     

my-portfolio@0.0.0构建   C:\ Acclaris \ Practice \ AngularPractice \ my-portfolio npm运行build:ssr

     

my-portfolio@0.0.0 build:ssr   C:\ Acclaris \ Practice \ AngularPractice \ my-portfolio npm运行   build:客户端和服务器捆绑&& npm运行compile:server

     

my-portfolio@0.0.0 build:客户端和服务器捆绑   C:\ Acclaris \ Practice \ AngularPractice \ my-portfolio ng build --prod &&   ng运行my-portfolio:server:production

     

日期:2019-05-10T10:14:15.321Z哈希值:49ca0a31b14b3f2ef33f时间:   28138ms块{0} runtime.274b2b523ee7c9b8154c.js(运行时)2.19 kB   [entry] [rendered] chunk {1} es2015-polyfills.c5dd28b362270c767b34.js   (es2015-polyfills)56.4 kB [初始] [渲染]块{2}   main.c6958b8ee410ac47c079.js(main)708 kB [initial] [rendered]块   {3} polyfills.8bbb231b43165d65d357.js(polyfills)41 kB [初始]   [呈现]块{4} styles.3e7ad83f8f97d37ca687.css(样式)61.6 kB   [初始] [渲染]块{5} 5.da6e7079542863691897.js()1.92 kB   [渲染]块{6} 6.89f434210c8e48ff257a.js()718字节   [渲染]块{7} 7.04704f420e92f76cb831.js()5.2 kB [渲染]

     

日期:2019-05-10T10:14:28.776Z哈希值:a1b5d85a17ec5299c6a4时间:8780ms   块{main} main.js,main.js.map(main)4.17 kB [entry] [rendered]

     

错误   src / app / shared / components / portfolio-builder / portfolio-builder.component.ts(2,27):   错误TS2307:找不到模块“ src / app / shared / interfaces”。   src / app / core / portfolio / portfolio.component.ts(2,27):错误TS2307:   找不到模块“ src / app / shared / interfaces”。   src / app / shared / components / portfolio-builder / body / body.component.ts(2,22):   错误TS2307:找不到模块“ src / app / shared / interfaces”。   src / app / shared / components / sections / education / education.component.ts(2,27):   错误TS2307:找不到模块“ src / app / shared / interfaces”。   src / app / shared / components / sections / education / education.component.ts(3,33):   错误TS2307:找不到模块   'src / app / shared / functions / function-library'。   src / app / shared / components / utilities / edulet / edulet.component.ts(2,27):   错误TS2307:找不到模块“ src / app / shared / interfaces”。   src / app / shared / components / portfolio-builder / footer / footer.component.ts(2,26):   错误TS2307:找不到模块“ src / app / shared / interfaces”。   src / app / shared / components / portfolio-builder / header / header.component.ts(2,24):   错误TS2307:找不到模块“ src / app / shared / interfaces”。   src / app / shared / components / sections / profile / profile.component.ts(2,25):   错误TS2307:找不到模块“ src / app / shared / interfaces”。   src / app / shared / components / portfolio-builder / sidebar / sidebar.component.ts(2,32):   错误TS2307:找不到模块“ src / app / shared / interfaces”。   src / app / shared / components / sections / sidebar-section / sidebar-section.component.ts(2,32):   错误TS2307:找不到模块“ src / app / shared / interfaces”。   src / app / shared / components / sections / work / work.component.ts(2,22):错误   TS2307:找不到模块“ src / app / shared / interfaces”。   src / app / shared / components / sections / work / work.component.ts(3,33):错误   TS2307:找不到模块   'src / app / shared / functions / function-library'。   src / app / shared / components / utilities / worklet / worklet.component.ts(2,22):   错误TS2307:找不到模块src / app / shared / interfaces。

     

npm错误!代码ELIFECYCLE npm ERR! errno 1 npm错误! my-portfolio@0.0.0   build:客户端和服务器捆绑包:ng build --prod && ng run my-portfolio:server:production npm ERR!退出状态1 npm ERR! npm   呃!在my-portfolio@0.0.0 build:client-and-server-bundles处失败   脚本。 npm ERR! npm可能不是问题。有   上面可能还有其他日志记录输出。

     

npm错误!有关此运行的完整日志,请参见:npm ERR!
  C:\ Users \ debmallya.bhattachar \ AppData \ Roaming \ npm-cache_logs \ 2019-05-10T10_14_28_865Z-debug.log   npm ERR!代码ELIFECYCLE npm ERR! errno 1 npm错误! my-portfolio@0.0.0   build:ssr:npm run build:client-and-server-bundles && npm run compile:server npm错误!退出状态1 npm ERR! npm ERR!失败于   my-portfolio@0.0.0 build:ssr脚本。 npm ERR!这可能不是   NPM的问题。上面可能还有其他日志记录输出。

     

npm错误!有关此运行的完整日志,请参见:npm ERR!
  C:\ Users \ debmallya.bhattachar \ AppData \ Roaming \ npm-cache_logs \ 2019-05-10T10_14_28_983Z-debug.log   npm ERR!代码ELIFECYCLE npm ERR! errno 1 npm错误! my-portfolio@0.0.0   构建:npm run build:ssr npm错误!退出状态1 npm ERR! npm ERR!   在my-portfolio@0.0.0生成脚本处失败。 npm ERR!这是   npm可能不是问题。可能还有其他日志记录   上面的输出。

     

npm错误!有关此运行的完整日志,请参见:npm ERR!
  C:\ Users \ debmallya.bhattachar \ AppData \ Roaming \ npm-cache_logs \ 2019-05-10T10_14_29_044Z-debug.log

1 个答案:

答案 0 :(得分:0)

将Portfolio接口的导入路径从以src / app / *开头的路径更改为直接路径。 例如,对于您的PortfolioBuilderComponent导入应如下所示:

import { Portfolio } from '../../interfaces/portfolio'