gpt4 book ai didi

angular5 - Angular Universal找不到模块

转载 作者:行者123 更新时间:2023-12-05 05:16:39 25 4
gpt4 key购买 nike

我已经使用 angular 5.2.10 设置了一个 angular 通用应用程序当我尝试使用 angular cli 和 webpack for server.ts 构建它时,似乎找不到我的模块。

什么有效:

ng build -prod --build-optimizer --app 0 

&&

ng build --aot --app 1 --output-hashing=false

什么不是:

webpack --config webpack.config.js --progress --colors

错误:

ERROR in /src/app/util/wnumb.ts
[tsl] ERROR in /src/app/util/wnumb.ts(1,26)
TS2307: Cannot find module '@angular/core'.

ERROR in /src/app/terms-and-conditions/terms-and-conditions.component.ts
[tsl] ERROR in /src/app/terms-and-conditions/terms-and-
conditions.component.ts(1,27)
TS2307: Cannot find module '@angular/core'.

ERROR in /src/app/terms-and-conditions/terms-and-conditions.component.ts
[tsl] ERROR in /src/app/terms-and-conditions/terms-and-
conditions.component.ts(2,24)
TS2307: Cannot find module '@angular/router'.

我的 webpack.config.js 文件:

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

module.exports = {
entry: { server: './src/server.ts' },
resolve: { extensions: ['.js','.ts'] },
target: 'node',
// this makes sure we include node_modules and other 3rd party libraries
externals: [/(node_modules|main\..*\.js)/],
output: {
path: path.join(__dirname, 'dist'),
filename: '[name].js'
},
module: {
rules: [{ test: /\.ts$/, loader: 'ts-loader' }]
},
plugins: [
new webpack.ContextReplacementPlugin(
/(.+)?angular(\\|\/)core(.+)?/,
path.join(__dirname, 'src'), // location of your src
{} // a map of your routes
),
new webpack.ContextReplacementPlugin(
/(.+)?express(\\|\/)(.+)?/,
path.join(__dirname, 'src'),
{}
)
]
};

还有我的 tsconfig.json:

{
"compilerOptions": {
"declaration": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"mapRoot": "./src/",
"removeComments": true,
"sourceMap": true,
"target": "es2017",
"typeRoots": [
"./node_modules/@types"
]
}
}

注意:如有任何帮助,我们将不胜感激。

最佳答案

万一其他人遇到这个问题,它看起来像将以下内容添加到我的 tsconfig.json 文件修复它:

"moduleResolution": "node",

tsconfig.json:

{
"compilerOptions": {
"declaration": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"mapRoot": "./src/",
"moduleResolution": "node",
"removeComments": true,
"sourceMap": true,
"target": "es2017",
"typeRoots": [
"./node_modules/@types"
]
}
}

关于angular5 - Angular Universal找不到模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50165913/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com