It may help if you could show how you configured in program.cs
I tried as the document :
In program.cs:
builder.Services.AddWebOptimizer(x =>x.AddJavaScriptBundle("/js/bundle.js", "js/chat/*.js"));
call
app.UseWebOptimizer();
before:
app.UseStaticFiles();
in chat.js:
console.log("chat");
in hellow.js:
console.log("hellow");
And my project:

in my View,I called:
<script src="/js/bundle.js"></script>
The result:

other document may help:
Update:
I tried to add two floders under the directory of the project as your comment and tried as below to fix the 404 error:
var provider1 = new Microsoft.Extensions.FileProviders.PhysicalFileProvider(Path.Combine(builder.Environment.ContentRootPath, "Script1"));
var provider2 = new Microsoft.Extensions.FileProviders.PhysicalFileProvider(Path.Combine(builder.Environment.ContentRootPath, "Script2"));
builder.Services.AddWebOptimizer
(x =>
{
x.AddJavaScriptBundle("/bundle1.js","/chat/*.js").UseFileProvider(provider1);
x.AddJavaScriptBundle("/bundle2.js","/comment/*.js").UseFileProvider(provider2);
});
My project:
