代码之家  ›  专栏  ›  技术社区  ›  iam.Carrot

服务器端渲染角度6.1

  •  0
  • iam.Carrot  · 技术社区  · 6 年前

    我正在和 Angular 6.1.0 遵循SSR的官方文件 here .

    我面临的问题是,当我运行命令时:

    npm run build:ssr && npm run serve:ssr

    这个 serve:ssr 给我一堆错误 .spec.ts 我的档案 node_modules .

    我已将我的项目上载到 GitHub here 因为我不知道是什么打破了它。

    PS:公文提供的源代码也会出现同样的错误。所以如果一定是我的嫉妒

    控制台输出:

    PS C:\Users\adity\Desktop\SSR_POC> npm run build:ssr
    
    > SSR_POC@0.0.0 build:ssr C:\Users\adity\Desktop\SSR_POC
    > npm run build:client-and-server-bundles && npm run webpack:server
    
    
    > SSR_POC@0.0.0 build:client-and-server-bundles C:\Users\adity\Desktop\SSR_POC
    > ng build --prod && ng run SSR_POC:server
    
    
    Date: 2018-12-29T19:36:13.480Z
    Hash: 58f58cfef181faaddfa4
    Time: 27072ms
    chunk {0} runtime.06daa30a2963fa413676.js (runtime) 1.44 kB [entry] [rendered]
    chunk {1} main.ac3253c328cbe390a1de.js (main) 169 kB [initial] [rendered]
    chunk {2} polyfills.677bdac3385565b157aa.js (polyfills) 59.6 kB [initial] [rendered]
    chunk {3} styles.3ff695c00d717f2d2a11.css (styles) 0 bytes [initial] [rendered]
    
    Date: 2018-12-29T19:36:23.462Z
    Hash: 884e7c93392763692b9e
    Time: 5573ms
    chunk {main} main.js, main.js.map (main) 22 kB [entry] [rendered]
    
    > SSR_POC@0.0.0 webpack:server C:\Users\adity\Desktop\SSR_POC
    > webpack --config webpack.server.config.js --progress --colors
    
    Hash: c21ceede9ca319c83513
    Version: webpack 4.16.4
    Time: 9187ms
    Built at: 2018-12-30 01:06:36
        Asset      Size  Chunks             Chunk Names
    server.js  4.72 MiB       0  [emitted]  server
    Entrypoint server = server.js
      [0] ./server.ts 1.91 KiB {0} [built]
      [2] external "events" 42 bytes {0} [built]
      [3] external "fs" 42 bytes {0} [built]
      [4] external "timers" 42 bytes {0} [optional] [built]
      [5] external "crypto" 42 bytes {0} [built]
    [210] ./src lazy namespace object 160 bytes {0} [built]
    [213] external "url" 42 bytes {0} [built]
    [273] external "http" 42 bytes {0} [built]
    [274] external "https" 42 bytes {0} [built]
    [275] external "os" 42 bytes {0} [built]
    [283] external "path" 42 bytes {0} [built]
    [292] external "util" 42 bytes {0} [built]
    [300] external "net" 42 bytes {0} [built]
    [305] external "buffer" 42 bytes {0} [built]
    [362] ./src sync 160 bytes {0} [built]
        + 375 hidden modules
    
    WARNING in ./node_modules/@angular/core/fesm5/core.js 4997:15-36
    System.import() is deprecated and will be removed soon. Use import() instead.
    For more info visit https://webpack.js.org/guides/code-splitting/
     @ ./server.ts 5:0-47 10:0-14
    
    WARNING in ./node_modules/@angular/core/fesm5/core.js 5009:15-102
    System.import() is deprecated and will be removed soon. Use import() instead.
    For more info visit https://webpack.js.org/guides/code-splitting/
     @ ./server.ts 5:0-47 10:0-14
    
    ERROR in ./server.ts
    Module not found: Error: Can't resolve './dist/server/main.bundle' in 'C:\Users\adity\Desktop\SSR_POC'
     @ ./server.ts 18:9-45
    
    ERROR in C:\Users\adity\Desktop\SSR_POC\e2e\src\app.e2e-spec.ts
    [tsl] ERROR in C:\Users\adity\Desktop\SSR_POC\e2e\src\app.e2e-spec.ts(3,1)
          TS2304: Cannot find name 'describe'.
    
    ERROR in C:\Users\adity\Desktop\SSR_POC\e2e\src\app.e2e-spec.ts
    [tsl] ERROR in C:\Users\adity\Desktop\SSR_POC\e2e\src\app.e2e-spec.ts(6,14)
          TS2345: Argument of type '() => void' is not assignable to parameter of type '(done: any) => Promise<void>'.
      Type 'void' is not assignable to type 'Promise<void>'.
    
    ERROR in C:\Users\adity\Desktop\SSR_POC\e2e\src\app.e2e-spec.ts
    [tsl] ERROR in C:\Users\adity\Desktop\SSR_POC\e2e\src\app.e2e-spec.ts(10,40)
          TS2345: Argument of type '() => void' is not assignable to parameter of type '(done: any) => Promise<void>'.
      Type 'void' is not assignable to type 'Promise<void>'.
    
    ERROR in C:\Users\adity\Desktop\SSR_POC\e2e\src\app.e2e-spec.ts
    [tsl] ERROR in C:\Users\adity\Desktop\SSR_POC\e2e\src\app.e2e-spec.ts(12,5)
          TS2304: Cannot find name 'expect'.
    
    ERROR in C:\Users\adity\Desktop\SSR_POC\src\app\app.component.spec.ts
    [tsl] ERROR in C:\Users\adity\Desktop\SSR_POC\src\app\app.component.spec.ts(3,1)
          TS2304: Cannot find name 'describe'.
    
    ERROR in C:\Users\adity\Desktop\SSR_POC\src\app\app.component.spec.ts
    [tsl] ERROR in C:\Users\adity\Desktop\SSR_POC\src\app\app.component.spec.ts(14,5)
          TS2304: Cannot find name 'expect'.
    
    ERROR in C:\Users\adity\Desktop\SSR_POC\src\app\app.component.spec.ts
    [tsl] ERROR in C:\Users\adity\Desktop\SSR_POC\src\app\app.component.spec.ts(19,5)
          TS2304: Cannot find name 'expect'.
    
    ERROR in C:\Users\adity\Desktop\SSR_POC\src\app\app.component.spec.ts
    [tsl] ERROR in C:\Users\adity\Desktop\SSR_POC\src\app\app.component.spec.ts(25,5)
          TS2304: Cannot find name 'expect'.
    
    ERROR in C:\Users\adity\Desktop\SSR_POC\node_modules\@types\jasmine\index.d.ts
    [tsl] ERROR in C:\Users\adity\Desktop\SSR_POC\node_modules\@types\jasmine\index.d.ts(140,47)
          TS1005: ';' expected.
    
    ERROR in C:\Users\adity\Desktop\SSR_POC\node_modules\@types\jasmine\index.d.ts
    [tsl] ERROR in C:\Users\adity\Desktop\SSR_POC\node_modules\@types\jasmine\index.d.ts(140,90)
          TS1005: '(' expected.
    
    ERROR in C:\Users\adity\Desktop\SSR_POC\node_modules\@types\jasmine\index.d.ts
    [tsl] ERROR in C:\Users\adity\Desktop\SSR_POC\node_modules\@types\jasmine\index.d.ts(140,104)
          TS1005: ']' expected.
    
    ERROR in C:\Users\adity\Desktop\SSR_POC\node_modules\@types\jasmine\index.d.ts
    [tsl] ERROR in C:\Users\adity\Desktop\SSR_POC\node_modules\@types\jasmine\index.d.ts(140,112)
          TS1005: ',' expected.
    
    ERROR in C:\Users\adity\Desktop\SSR_POC\node_modules\@types\jasmine\index.d.ts
    [tsl] ERROR in C:\Users\adity\Desktop\SSR_POC\node_modules\@types\jasmine\index.d.ts(140,113)
          TS1136: Property assignment expected.
    
    ERROR in C:\Users\adity\Desktop\SSR_POC\node_modules\@types\jasmine\index.d.ts
    [tsl] ERROR in C:\Users\adity\Desktop\SSR_POC\node_modules\@types\jasmine\index.d.ts(140,121)
          TS1005: ')' expected.
    
    ERROR in C:\Users\adity\Desktop\SSR_POC\node_modules\@types\jasmine\index.d.ts
    [tsl] ERROR in C:\Users\adity\Desktop\SSR_POC\node_modules\@types\jasmine\index.d.ts(140,147)
          TS1005: '(' expected.
    
    ERROR in C:\Users\adity\Desktop\SSR_POC\node_modules\@types\jasmine\index.d.ts
    [tsl] ERROR in C:\Users\adity\Desktop\SSR_POC\node_modules\@types\jasmine\index.d.ts(140,162)
          TS1005: ']' expected.
    
    ERROR in C:\Users\adity\Desktop\SSR_POC\node_modules\@types\jasmine\index.d.ts
    [tsl] ERROR in C:\Users\adity\Desktop\SSR_POC\node_modules\@types\jasmine\index.d.ts(140,163)
          TS1005: ',' expected.
    
    ERROR in C:\Users\adity\Desktop\SSR_POC\node_modules\@types\jasmine\index.d.ts
    [tsl] ERROR in C:\Users\adity\Desktop\SSR_POC\node_modules\@types\jasmine\index.d.ts(140,164)
          TS1136: Property assignment expected.
    
    ERROR in C:\Users\adity\Desktop\SSR_POC\node_modules\@types\jasmine\index.d.ts
    [tsl] ERROR in C:\Users\adity\Desktop\SSR_POC\node_modules\@types\jasmine\index.d.ts(140,165)
          TS1136: Property assignment expected.
    
    ERROR in C:\Users\adity\Desktop\SSR_POC\node_modules\@types\jasmine\index.d.ts
    [tsl] ERROR in C:\Users\adity\Desktop\SSR_POC\node_modules\@types\jasmine\index.d.ts(140,179)
          TS1005: ',' expected.
    
    ERROR in C:\Users\adity\Desktop\SSR_POC\node_modules\@types\jasmine\index.d.ts
    [tsl] ERROR in C:\Users\adity\Desktop\SSR_POC\node_modules\@types\jasmine\index.d.ts(140,183)
          TS1005: ':' expected.
    
    ERROR in C:\Users\adity\Desktop\SSR_POC\node_modules\@types\jasmine\index.d.ts
    [tsl] ERROR in C:\Users\adity\Desktop\SSR_POC\node_modules\@types\jasmine\index.d.ts(140,208)
          TS1005: '{' expected.
    
    ERROR in C:\Users\adity\Desktop\SSR_POC\node_modules\@types\jasmine\index.d.ts
    [tsl] ERROR in C:\Users\adity\Desktop\SSR_POC\node_modules\@types\jasmine\index.d.ts(140,217)
          TS1005: ':' expected.
    
    ERROR in C:\Users\adity\Desktop\SSR_POC\node_modules\@types\jasmine\index.d.ts
    [tsl] ERROR in C:\Users\adity\Desktop\SSR_POC\node_modules\@types\jasmine\index.d.ts(140,222)
          TS1005: ',' expected.
    
    ERROR in C:\Users\adity\Desktop\SSR_POC\node_modules\@types\jasmine\index.d.ts
    [tsl] ERROR in C:\Users\adity\Desktop\SSR_POC\node_modules\@types\jasmine\index.d.ts(140,227)
          TS1005: ':' expected.
    
    ERROR in C:\Users\adity\Desktop\SSR_POC\node_modules\@types\jasmine\index.d.ts
    [tsl] ERROR in C:\Users\adity\Desktop\SSR_POC\node_modules\@types\jasmine\index.d.ts(140,228)
          TS1109: Expression expected.
    
    ERROR in C:\Users\adity\Desktop\SSR_POC\node_modules\@types\jasmine\index.d.ts
    [tsl] ERROR in C:\Users\adity\Desktop\SSR_POC\node_modules\@types\jasmine\index.d.ts(140,230)
          TS1005: ')' expected.
    
    ERROR in C:\Users\adity\Desktop\SSR_POC\node_modules\@types\jasmine\index.d.ts
    [tsl] ERROR in C:\Users\adity\Desktop\SSR_POC\node_modules\@types\jasmine\index.d.ts(633,30)
          TS1005: ';' expected.
    
    ERROR in C:\Users\adity\Desktop\SSR_POC\node_modules\@types\jasmine\index.d.ts
    [tsl] ERROR in C:\Users\adity\Desktop\SSR_POC\node_modules\@types\jasmine\index.d.ts(718,1)
          TS1128: Declaration or statement expected.
    npm ERR! code ELIFECYCLE
    npm ERR! errno 2
    npm ERR! SSR_POC@0.0.0 webpack:server: `webpack --config webpack.server.config.js --progress --colors`
    npm ERR! Exit status 2
    npm ERR!
    npm ERR! Failed at the SSR_POC@0.0.0 webpack:server script.
    npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
    
    npm ERR! A complete log of this run can be found in:
    npm ERR!     C:\Users\adity\AppData\Roaming\npm-cache\_logs\2018-12-29T19_36_36_231Z-debug.log
    npm ERR! code ELIFECYCLE
    npm ERR! errno 2
    npm ERR! SSR_POC@0.0.0 build:ssr: `npm run build:client-and-server-bundles && npm run webpack:server`
    npm ERR! Exit status 2
    npm ERR!
    npm ERR! Failed at the SSR_POC@0.0.0 build:ssr script.
    npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
    
    npm ERR! A complete log of this run can be found in:
    npm ERR!     C:\Users\adity\AppData\Roaming\npm-cache\_logs\2018-12-29T19_36_36_276Z-debug.log
    
    1 回复  |  直到 6 年前
        1
  •  2
  •   Michael    6 年前

        {
                // Mark files inside `@angular/core` as using SystemJS style dynamic imports.
                // Removing this will cause deprecation warnings to appear.
                test: /(\\|\/)@angular(\\|\/)core(\\|\/).+\.js$/,
                parser: {system: true},
        },
    

    在server.ts中我有

    const {AppServerModuleNgFactory, LAZY_MODULE_MAP} = require("./dist/server/main")
    

    哪个解决不了。/main.bundle错误。

    {
      "extends": "./tsconfig.app.json",
      "compilerOptions": {
        "outDir": "../out-tsc/app-server",
        "baseUrl": "."
      },
      "angularCompilerOptions": {
        "entryModule": "app/app.server.module#AppServerModule"
      }
    }
    

    npm update typescript

    推荐文章