gpt4 book ai didi

Angular 5 类型错误 : AngularCompilerPlugin is not a constructor

转载 作者:太空狗 更新时间:2023-10-29 18:19:24 28 4
gpt4 key购买 nike

Angular 5 aspnetcore 2.0 是我的环境。

并且我将我的包更新为 Angular 5,并将 webpack.config.js 中的 AotPlugin 替换为 AngularCompilerPlugin。在发布我的项目时,我遇到了这个错误。

 TypeError: AngularCompilerPlugin is not a constructor
2017-12-07T06:25:19.8388691Z at module.exports (d:\a\1\s\web\source\webpack.config.js:48:13)
2017-12-07T06:25:19.8388916Z at requireConfig (d:\a\1\s\web\source\node_modules\webpack\bin\convert-argv.js:102:15)
2017-12-07T06:25:19.8389187Z at d:\a\1\s\web\source\node_modules\webpack\bin\convert-argv.js:109:17
2017-12-07T06:25:19.8389479Z at Array.forEach (native)
2017-12-07T06:25:19.8389687Z at module.exports (d:\a\1\s\web\source\node_modules\webpack\bin\convert-argv.js:107:15)
2017-12-07T06:25:19.8389914Z at Object.<anonymous> (d:\a\1\s\web\source\node_modules\webpack\bin\webpack.js:153:40)
2017-12-07T06:25:19.8390154Z at Module._compile (module.js:570:32)
2017-12-07T06:25:19.8390340Z at Object.Module._extensions..js (module.js:579:10)
2017-12-07T06:25:19.8390524Z at Module.load (module.js:487:32)
2017-12-07T06:25:19.8390881Z at tryModuleLoad (module.js:446:12)
2017-12-07T06:25:19.8569143Z d:\a\1\s\web\source\CA.IDM.PAdmin.Web.csproj(41,5): error MSB3073: The command "node node_modules/webpack/bin/webpack.js --env.prod" exited with code 1.
2017-12-07T06:25:19.9453100Z ##[error]Error: C:\Program Files\dotnet\dotnet.exe failed with return code: 1
2017-12-07T06:25:19.9454881Z ##[error]Dotnet command failed with non-zero exit code on the following projects : d:\a\1\s\web\source\CA.IDM.PAdmin.Web.csproj

所以我撤销了这个更改并在 webpack.config.js 中恢复了 AotPlugin 现在我的发布成功了。

实际上对于 Angular 5 使用 AngularCompilerPlugin 而不是 AotPlugin。所以我的问题是我错过了什么吗?我在这里做错了什么?

webpack.config.js

const path = require('path');
const webpack = require('webpack');
const merge = require('webpack-merge');
const AngularCompilerPlugin = require('@ngtools/webpack').AngularCompilerPlugin ;
const CheckerPlugin = require('awesome-typescript-loader').CheckerPlugin;

module.exports = (env) => {
// Configuration in common to both client-side and server-side bundles
const isDevBuild = !(env && env.prod);
const sharedConfig = {
stats: { modules: false },
context: __dirname,
resolve: { extensions: [ '.js', '.ts' ] },
output: {
filename: '[name].js',
publicPath: 'dist/' // Webpack dev middleware, if enabled, handles requests for this URL prefix
},
module: {
rules: [
{ test: /\.ts$/, use: isDevBuild ? ['awesome-typescript-loader?silent=true', 'angular2-template-loader', 'angular2-router-loader'] : '@ngtools/webpack' },
{ test: /\.html$/, use: 'html-loader?minimize=false' },
{ test: /\.css$/, use: [ 'to-string-loader', isDevBuild ? 'css-loader' : 'css-loader?minimize' ] },
{ test: /\.(png|jpg|jpeg|gif|svg)$/, use: 'url-loader?limit=25000' }
]
},
plugins: [new CheckerPlugin()]
};

// Configuration for client-side bundle suitable for running in browsers
const clientBundleOutputDir = './wwwroot/dist';
const clientBundleConfig = merge(sharedConfig, {
entry: { 'main-client': './ClientApp/boot.browser.ts' },
output: { path: path.join(__dirname, clientBundleOutputDir) },
plugins: [
new webpack.DllReferencePlugin({
context: __dirname,
manifest: require('./wwwroot/dist/vendor-manifest.json')
})
].concat(isDevBuild ? [
// Plugins that apply in development builds only
new webpack.SourceMapDevToolPlugin({
filename: '[file].map', // Remove this line if you prefer inline source maps
moduleFilenameTemplate: path.relative(clientBundleOutputDir, '[resourcePath]') // Point sourcemap entries to the original file locations on disk
})
] : [
// Plugins that apply in production builds only
new webpack.optimize.UglifyJsPlugin(),
new AngularCompilerPlugin ({
tsConfigPath: './tsconfig.json',
entryModule: path.join(__dirname, 'ClientApp/app/app.browser.module#AppModule'),
exclude: ['./**/*.server.ts']
})
])
});

// Configuration for server-side (prerendering) bundle suitable for running in Node
const serverBundleConfig = merge(sharedConfig, {
resolve: { mainFields: ['main'] },
entry: { 'main-server': './ClientApp/boot.server.ts' },
plugins: [
new webpack.DllReferencePlugin({
context: __dirname,
manifest: require('./ClientApp/dist/vendor-manifest.json'),
sourceType: 'commonjs2',
name: './vendor'
})
].concat(isDevBuild ? [] : [
// Plugins that apply in production builds only
new AngularCompilerPlugin ({
tsConfigPath: './tsconfig.json',
entryModule: path.join(__dirname, 'ClientApp/app/app.server.module#AppModule'),
exclude: ['./**/*.browser.ts']
})
]),
output: {
libraryTarget: 'commonjs',
path: path.join(__dirname, './ClientApp/dist')
},
target: 'node',
devtool: 'inline-source-map'
});

return [clientBundleConfig, serverBundleConfig];
};

包.json

{
"name": "Web5",
"private": true,
"version": "0.0.0",
"scripts": {
"test": "karma start ClientApp/test/karma.conf.js"
},
"devDependencies": {
"@angular/animations": "5.0.5",
"@angular/common": "5.0.5",
"@angular/compiler": "5.0.5",
"@angular/compiler-cli": "5.0.5",
"@angular/core": "5.0.5",
"@angular/forms": "5.0.5",
"@angular/http": "5.0.5",
"@angular/platform-browser": "5.0.5",
"@angular/platform-browser-dynamic": "5.0.5",
"@angular/platform-server": "5.0.5",
"@angular/router": "5.0.5",
"@ngtools/webpack": "1.8.5",
"@types/chai": "4.0.1",
"@types/jasmine": "2.5.53",
"@types/webpack-env": "1.13.0",
"angular2-router-loader": "0.3.5",
"angular2-template-loader": "0.6.2",
"aspnet-prerendering": "^3.0.1",
"aspnet-webpack": "^2.0.1",
"awesome-typescript-loader": "3.2.1",
"bootstrap": "3.3.7",
"chai": "4.0.2",
"css": "2.2.1",
"css-loader": "0.28.4",
"es6-shim": "0.35.3",
"event-source-polyfill": "0.0.9",
"expose-loader": "0.7.3",
"extract-text-webpack-plugin": "2.1.2",
"file-loader": "0.11.2",
"html-loader": "0.4.5",
"isomorphic-fetch": "2.2.1",
"jasmine-core": "2.6.4",
"jquery": "3.2.1",
"json-loader": "0.5.4",
"karma": "1.7.0",
"karma-chai": "0.1.0",
"karma-chrome-launcher": "2.2.0",
"karma-cli": "1.0.1",
"karma-jasmine": "1.1.0",
"karma-webpack": "2.0.3",
"preboot": "4.5.2",
"raw-loader": "0.5.1",
"reflect-metadata": "0.1.10",
"rxjs": "5.5.4",
"style-loader": "0.18.2",
"to-string-loader": "1.1.5",
"typescript": "2.6.2",
"url-loader": "0.5.9",
"webpack": "2.5.1",
"webpack-hot-middleware": "2.18.2",
"webpack-merge": "4.1.0",
"zone.js": "0.8.12"
}
}

正如我在发布时检查的那样,它没有采用更新版本。会是什么原因呢?

12-07T06:23:03.8757490Z   Web5 -> d:\a\1\s\web5.dll
2017-12-07T06:24:43.8922441Z Web5@0.0.0 d:\a\1\s\web\
2017-12-07T06:24:43.8923186Z +-- @angular/animations@4.2.5
2017-12-07T06:24:43.8923751Z +-- @angular/common@4.2.5
2017-12-07T06:24:43.8925363Z +-- @angular/compiler@4.2.5
2017-12-07T06:24:43.8935332Z +-- @angular/compiler-cli@4.2.5
2017-12-07T06:24:43.8936589Z | `-- minimist@1.2.0
2017-12-07T06:24:43.8936969Z +-- @angular/core@4.2.5
2017-12-07T06:24:43.8937290Z +-- @angular/forms@4.2.5
2017-12-07T06:24:43.8937696Z +-- @angular/http@4.2.5
2017-12-07T06:24:43.8938023Z +-- @angular/platform-browser@4.2.5
2017-12-07T06:24:43.8938348Z +-- @angular/platform-browser-dynamic@4.2.5
2017-12-07T06:24:43.8938687Z +-- @angular/platform-server@4.2.5
2017-12-07T06:24:43.8939007Z +-- @angular/router@4.2.5
2017-12-07T06:24:43.8939341Z +-- @angular/tsc-wrapped@4.2.5

最佳答案

如果不看您的 webpack.config 就很难分辨。

这是我喜欢的方式:

const AotPlugin = require('@ngtools/webpack').AngularCompilerPlugin;

plugins: [
new AotPlugin({
tsConfigPath: './tsconfig.json',
entryModule: path.join(__dirname, 'src/app/app.module#AppModule')
})
]

关于 Angular 5 类型错误 : AngularCompilerPlugin is not a constructor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47690469/

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