![](/img/trans.png)
[英]I am getting an below error when i run npm install and ng serve on my angular2 application
[英]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? 如果不:
npm i @types/node
然后轉到./app/src/tsconfig.server.json
"compilerOptions": { "types": [ "node" ] },
重新啟動npm run start-ssr
命令。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.