簡體   English   中英

嘗試使用npm run start-ssr運行我的Angular時,控制台出現錯誤

[英]I am getting error in the console while trying to run my angular with npm run start-ssr

我試圖在我的angular 7應用程序中包含angular Universal。 我使用npm run start-ssr ,但是在節點控制台中出現以下錯誤。

找不到名稱要求。 您是否需要為節點安裝類型定義? 嘗試npm i @ types / node`,然后將節點添加到tsconfig中的types字段中

找不到名稱“進程”。 您是否需要為節點安裝類型定義? 嘗試npm i @ types / node,然后將節點添加到tsconfig中的types字段中

src / server.ts(26,1):錯誤TS2304:找不到名稱“全局”

我的應用程序webpack.server.config.ts中包含以下代碼

const path = require('path');
const webpack = require('webpack');

module.exports = {
  mode: 'none',
  entry: {
    server: './server.ts',
  },
  target: 'node',
  resolve: { extensions: ['.ts', '.js'] },
  optimization: {
    minimize: false
  },
  output: {
    // Puts the output at the root of the dist folder
    path: path.join(__dirname, 'dist'),
    filename: '[name].js'
  },
  module: {
    rules: [
      { test: /\.ts$/, loader: 'ts-loader' },
      {
        // 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 },
      },
    ]
  },
  plugins: [
    new webpack.ContextReplacementPlugin(
      // fixes WARNING Critical dependency: the request of a dependency is an expression
      /(.+)?angular(\\|\/)core(.+)?/,
      path.join(__dirname, 'src'), // location of your src
      {} // a map of your routes
    ),
    new webpack.ContextReplacementPlugin(
      // fixes WARNING Critical dependency: the request of a dependency is an expression
      /(.+)?express(\\|\/)(.+)?/,
      path.join(__dirname, 'src'),
      {}
    )
  ]
}

在我的tsconfig.json中

{
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "./",
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "module": "es2015",
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "importHelpers": true,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2018",
      "dom"
    ]
  }
}

您是否按照錯誤消息中的說明安裝了@ types / node? 如果不:

  1. 運行npm i @types/node
  2. 然后轉到./app/src/tsconfig.server.json

    "compilerOptions": { "types": [ "node" ] },

  3. 重新啟動npm run start-ssr命令。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM