2017-11-19 11 views
1

私のアプリを公開しようとしています。最初にあらゆる問題に遭遇しました。すべてのパッケージを最新のバージョン(角5など)に更新しました。人々はあなたがaotプラグインを変更する必要がありますと言ったように、webpackにいくつかの変更を加えました。Publish「AppModule」のNgModuleメタデータが見つかりません

私はこの奇妙な問題に遭遇しましたが、開発版では公開せずにサーバーを稼働させることができます。 (DOTNETの実行xxx.dll) しかし、私は公開し、ウェブサイトに入るとき、私はいつもこのエラーに遭遇実行しようとする:(私はそれが私のWebPACKの設定や開発/生産の設定に関連するかもしれない疑い

Application started. Press Ctrl+C to shut down. 
fail: Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware[0] 
     An unhandled exception has occurred: No NgModule metadata found for 'AppModule'. 
     Error: No NgModule metadata found for 'AppModule'. 
      at NgModuleResolver.module.exports.NgModuleResolver.resolve (/var/TestApp/ClientApp/dist/vendor.js:61057:23) 
      at CompileMetadataResolver.module.exports.CompileMetadataResolver.getNgModuleMetadata (/var/TestApp/ClientApp/dist/vendor.js:56047:60) 
      at JitCompiler.module.exports.JitCompiler._loadModules (/var/TestApp/ClientApp/dist/vendor.js:74490:87) 
      at JitCompiler.module.exports.JitCompiler._compileModuleAndComponents (/var/TestApp/ClientApp/dist/vendor.js:74451:36) 
      at JitCompiler.module.exports.JitCompiler.compileModuleAsync (/var/TestApp/ClientApp/dist/vendor.js:74367:37) 
      at CompilerImpl.module.exports.CompilerImpl.compileModuleAsync (/var/TestApp/ClientApp/dist/vendor.js:98089:49) 
      at PlatformRef.module.exports.PlatformRef.bootstrapModule (/var/TestApp/ClientApp/dist/vendor.js:16396:25) 
      at /var/TestApp/ClientApp/dist/main-server.js:21258:111 
      at /var/TestApp/ClientApp/dist/vendor.js:86229:35 
      at /var/TestApp/ClientApp/dist/vendor.js:86348:33 
Microsoft.AspNetCore.NodeServices.HostingModels.NodeInvocationException: No NgModule metadata found for 'AppModule'. 
Error: No NgModule metadata found for 'AppModule'. 
    at NgModuleResolver.module.exports.NgModuleResolver.resolve (/var/TestApp/ClientApp/dist/vendor.js:61057:23) 
    at CompileMetadataResolver.module.exports.CompileMetadataResolver.getNgModuleMetadata (/var/TestApp/ClientApp/dist/vendor.js:56047:60) 
    at JitCompiler.module.exports.JitCompiler._loadModules (/var/TestApp/ClientApp/dist/vendor.js:74490:87) 
    at JitCompiler.module.exports.JitCompiler._compileModuleAndComponents (/var/TestApp/ClientApp/dist/vendor.js:74451:36) 
    at JitCompiler.module.exports.JitCompiler.compileModuleAsync (/var/TestApp/ClientApp/dist/vendor.js:74367:37) 
    at CompilerImpl.module.exports.CompilerImpl.compileModuleAsync (/var/TestApp/ClientApp/dist/vendor.js:98089:49) 
    at PlatformRef.module.exports.PlatformRef.bootstrapModule (/var/TestApp/ClientApp/dist/vendor.js:16396:25) 
    at /var/TestApp/ClientApp/dist/main-server.js:21258:111 
    at /var/TestApp/ClientApp/dist/vendor.js:86229:35 
    at /var/TestApp/ClientApp/dist/vendor.js:86348:33 
    at Microsoft.AspNetCore.NodeServices.HostingModels.HttpNodeInstance.<InvokeExportAsync>d__7`1.MoveNext() 

を?

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|\.tsx$/, use: isDevBuild ? ['awesome-typescript-loader?silent=true', 'angular2-template-loader'] : '@ngtools/webpack' }, 
       { test: /\.html$/, use: 'html-loader?minimize=false' }, 
       { test: /\.css$/, use: ['to-string-loader', isDevBuild ? 'css-loader' : 'css-loader?minimize', 'less-loader'] }, 
       { test: /\.less$/, use: ['to-string-loader', isDevBuild ? 'css-loader' : 'css-loader?minimize', 'less-loader'] }, 
       { 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.module.browser#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.module.server#AppModule'), 
       exclude: ['./**/*.browser.ts'] 
      }) 
     ]), 
     output: { 
      libraryTarget: 'commonjs', 
      path: path.join(__dirname, './ClientApp/dist') 
     }, 
     target: 'node', 
     devtool: 'inline-source-map' 
    }); 

    return [clientBundleConfig, serverBundleConfig]; 
}; 

なぜこれが起こっている、誰かが正しい方向に私を指す

:私はAngularCompilerPlugin

私のWebPACKの設定に変更+ 5の角度WebPACKのコンフィグAOTPluginに更新します

答えて

0

Server Side Renderingは、Angular 5の異なる方法で動作し、現在のASP.NET Coreテンプレートでは機能しないため、問題が発生します。

https://github.com/aspnet/JavaScriptServices/issues/1385

無効サーバー側のレンダリングは、単にViews\Home\Index.cshtmlファイルにasp-prerender-moduleタグヘルパーを削除することによって行うことができます。

も参照してください。 No NgModule metadata found for 'AppModule' Error in Angular 5 server-side rendering with --env.prod

関連する問題