2017-12-14 121 views
5

Tôi có một ASP.NET Core 2.0/Angular mẫu ứng dụng. Mọi việc đều ổn cho đến khi tôi thử và xuất bản. Tôi nhận được lỗi sau:xuất bản thất bại trên ASP.NET Core 2.0/Angular mẫu ứng dụng

in ./ClientApp/boot.browser.ts 
Module parse failed: E:\rootfolder\ClientApp\boot.browser.ts Unexpected token (14:19) 
You may need an appropriate loader to handle this file type. 
|   const oldRootElem = document.querySelector('app'); 
|   const newRootElem = document.createElement('app'); 
|   oldRootElem!.parentNode!.insertBefore(newRootElem, oldRootElem); 
|   modulePromise.then(appModule => appModule.destroy()); 
|  }); 
@ multi event-source-polyfill webpack-hot-middleware/client?path=__webpack_hmr&dynamicPublicPath=true ./ClientApp/boot.browser.ts 

Tôi đã thực hiện tìm kiếm google thông thường không có may mắn cho đến nay. Bất kỳ ý tưởng nơi tôi nên được tìm kiếm? Đây là một ứng dụng ASP.NET CORE 2.0 sử dụng mẫu góc cạnh được tạo ra VS 2017. Tôi đã đăng tệp package.json bên dưới. Tôi nhận được kết quả tương tự Thời tiết tôi một cách rõ ràng gọi là "donet xuất bản" lệnh hoặc nhấn nút xuất bản từ bên trong VS 2017.

{ 
    "name": "MyApp", 
    "private": true, 
    "version": "0.0.0", 
    "scripts": { 
    "test": "karma start ClientApp/test/karma.conf.js" 
    }, 
    "dependencies": { 
    "@angular/animations": "^4.4.4", 
    "@angular/common": "^4.4.4", 
    "@angular/compiler": "^4.4.4", 
    "@angular/compiler-cli": "^4.4.4", 
    "@angular/core": "^4.4.4", 
    "@angular/forms": "^4.4.4", 
    "@angular/http": "^4.4.4", 
    "@angular/platform-browser": "^4.4.4", 
    "@angular/platform-browser-dynamic": "^4.4.4", 
    "@angular/platform-server": "^4.4.4", 
    "@angular/router": "^4.4.4", 
    "@ngtools/webpack": "1.5.0", 
    "@types/webpack-env": "1.13.0", 
    "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", 
    "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", 
    "jquery": "3.2.1", 
    "json-loader": "0.5.4", 
    "preboot": "4.5.2", 
    "raw-loader": "0.5.1", 
    "reflect-metadata": "0.1.10", 
    "rxjs": "5.4.2", 
    "style-loader": "0.18.2", 
    "to-string-loader": "1.1.5", 
    "typescript": "2.5.0", 
    "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", 
    "angular2-jwt": "^0.2.3" 
    }, 
    "devDependencies": { 
    "@types/chai": "4.0.1", 
    "@types/jasmine": "2.5.53", 
    "chai": "4.0.2", 
    "jasmine-core": "2.6.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" 
    } 
} 

WebPack nội dung như sau:

const path = require('path'); 
const webpack = require('webpack'); 
const merge = require('webpack-merge'); 
const AotPlugin = require('@ngtools/webpack').AotPlugin; 
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$/, include: /ClientApp/, 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' ] }, 
       { 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 AotPlugin({ 
       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 AotPlugin({ 
       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]; 
}; 

Trả lời

3

Vấn đề này đã được giải quyết bằng cách cập nhật các phiên bản nút/npm của tôi đến phiên bản mới nhất được đề xuất. nút: v8.9.3 npm: 5.5.1

Các vấn đề liên quan