AspNetCore + Angular 2:新项目的 WebpackDevMiddleware 错误 [英] AspNetCore + Angular 2: WebpackDevMiddleware Error with new project
问题描述
我正在使用本教程创建一个新项目:
I'm creating a new project with this tutorial:
接下来一些已解决的问题,我现在有一个完整的项目,安装了所有依赖项,但是当我使用 IIS 启动项目时,出现此错误.
Next some resolved issues, I have now a complete project with all dependencies installed but when I launch the project with IIS, I have this error .
L'exception System.AggregateException s'est produite
HResult=0x80131500
Message=One or more errors occurred.
Source=<Impossible d'évaluer la source de l'exception>
Arborescence des appels de procédure :
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
at Microsoft.AspNetCore.Builder.WebpackDevMiddleware.UseWebpackDevMiddleware(IApplicationBuilder appBuilder, WebpackDevMiddlewareOptions options)
at Test.Startup.Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) in C:\VS2017\Project\Test\Startup.cs:line 44
Exception interne 1 :
Exception : Call to Node module failed with error: Webpack dev middleware failed because of an error while loading 'aspnet-webpack'. Error was: C:\VS2017\Project\Test\node_modules\webpack\lib\webpack.js:7
const Compiler = require("./Compiler");
^^^^^
SyntaxError: Use of const in strict mode.
at exports.runInThisContext (vm.js:73:16)
at Module._compile (module.js:443:25)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object.<anonymous> (C:\VS2017\Project\Test\node_modules\aspnet-webpack\WebpackDevMiddleware.js:4:15)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
Current directory is: C:\VS2017\Project\Test
我不知道我哪一步失败了,所以如果有人已经做到了.
I don't know wich step I failed so if someone already did it.
推荐答案
发生这种情况是因为 aspnet-webpack
节点包需要更新版本的 node
.
This happens because the aspnet-webpack
node package requires a newer version of node
.
const 和 let 是 ECMAScript 2015(又名 ES6 和 Harmony)的一部分,在 Node.js 0.10 或 0.12 中默认没有启用.自 Node.js 4.x 起,V8 认为稳定的所有交付 [ES2015] 功能在 Node.js 上默认开启,不需要任何类型的运行时标志.".
The const and let are part of ECMAScript 2015 (a.k.a. ES6 and Harmony), and was not enabled by default in Node.js 0.10 or 0.12. Since Node.js 4.x, "All shipping [ES2015] features, which V8 considers stable, are turned on by default on Node.js and do NOT require any kind of runtime flag.".
因此,通过升级到 Node.js 4.x 或更高版本,错误应该会消失.
So by upgrading to Node.js 4.x or newer the error should disappear.
https://stackoverflow.com/a/23151062/5082427
更新
您可以通过在命令行中执行 node -v
来检查已安装的 node 版本.如果此命令输出的版本比您安装的版本旧,请检查 PATH
环境变量以确保您没有安装多个节点.
You can check the installed version of node by executing node -v
in the command-line. If this command outputs an older version than the one you have installed, check the PATH
environment variable to ensure you don't have multiple node installations.
这篇关于AspNetCore + Angular 2:新项目的 WebpackDevMiddleware 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!