我使用angular 5.2.10设置了一个angular通用应用程序,当我尝试用angular cli和server.ts版的webpack构建它时,似乎找不到我的模块。
有效的方法:
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"
]
}
}注意:如有任何帮助,我们将不胜感激。
发布于 2018-05-04 10:10:54
如果其他人遇到这个问题,它看起来像是在我的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"
]
}
}https://stackoverflow.com/questions/50165913
复制相似问题