gpt4 book ai didi

c# - 无法在 ASP.NET Core 中使用 webpack 中间件

转载 作者:行者123 更新时间:2023-11-30 21:33:31 43 4
gpt4 key购买 nike

我尝试在 ASP.NET Core 项目中使用 webpack

这是我的 Startup.cs 文件和配置类

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions
{
HotModuleReplacement = true
});
}
else
{
app.UseExceptionHandler("/Home/Error");
app.UseHsts();
}

app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseCookiePolicy();

app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}

这是我的 package.json 文件

    {
"name": "streamline",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"wbp": "webpack"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"aspnet-webpack": "^3.0.0",
"bootstrap": "^4.1.2",
"css-loader": "^1.0.0",
"extract-text-webpack-plugin": "^4.0.0-beta.0",
"jquery": "^3.3.1",
"popper.js": "^1.14.3",
"style-loader": "^0.21.0",
"uglifyjs-webpack-plugin": "^1.2.7",
"webpack": "^4.16.1",
"webpack-cli": "^3.0.8",
"webpack-hot-middleware": "^2.22.2"
},
"dependencies": {
"@babel/core": "^7.0.0-beta.53",
"@babel/preset-env": "^7.0.0-beta.53",
"babel-loader": "^8.0.0-beta.4"
}
}

当我尝试运行项目时,出现此错误。但我不知道为什么。我该如何解决这个问题?

Exception has occurred: CLR/System.AggregateException
An exception of type 'System.AggregateException' occurred in System.Private.CoreLib.dll but was not handled in user code: 'One or more errors occurred.'
Inner exceptions found, see $exception in variables window for more details.
Innermost exception Microsoft.AspNetCore.NodeServices.HostingModels.NodeInvocationException : Error: Cannot find module 'webpack-dev-middleware'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:594:15)
at Function.Module._load (internal/modules/cjs/loader.js:520:25)
at Module.require (internal/modules/cjs/loader.js:650:17)
at require (internal/modules/cjs/helpers.js:20:18)
at attachWebpackDevMiddleware (/Users/nemesises/Documents/GitHub/streamline/StreamLine/node_modules/aspnet-webpack/WebpackDevMiddleware.js:72:13)
at /Users/nemesises/Documents/GitHub/streamline/StreamLine/node_modules/aspnet-webpack/WebpackDevMiddleware.js:271:25
at Array.forEach (<anonymous>)
at Server.<anonymous> (/Users/nemesises/Documents/GitHub/streamline/StreamLine/node_modules/aspnet-webpack/WebpackDevMiddleware.js:234:36)
at Object.onceWrapper (events.js:273:13)
at Server.emit (events.js:182:13)
at emitListeningNT (net.js:1362:10)
at process._tickCallback (internal/process/next_tick.js:63:19)
at Microsoft.AspNetCore.NodeServices.HostingModels.HttpNodeInstance.<InvokeExportAsync>d__7`1.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at Microsoft.AspNetCore.NodeServices.HostingModels.OutOfProcessNodeInstance.<InvokeExportAsync>d__13`1.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at Microsoft.AspNetCore.NodeServices.NodeServicesImpl.<InvokeExportWithPossibleRetryAsync>d__10`1.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.AspNetCore.NodeServices.NodeServicesImpl.<InvokeExportWithPossibleRetryAsync>d__10`1.MoveNext()

最佳答案

我有同样的问题。我的解决方案...

npm install --save-dev webpack-cli

这给了我线索npm WARN aspnet-webpack@3.0.0 需要 webpack-dev-middleware 的同级@^1.8.4 || ^3.0.0 但没有安装。您必须自己安装对等依赖项。npm WARN acesweb@1.0.0 没有存储库字段。

然后..

npm install --save-dev webpack-dev-middleware

现在它运行正常。

关于c# - 无法在 ASP.NET Core 中使用 webpack 中间件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51362040/

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