Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bundler & Minifier generating "Object reference not set to an instance of an object" error

I trying bundle and minify my CSS and JS files in ASP.NET Core 3.0 with BuildBundlerMinifier.Core. Also Installed Bundler & Minifier extension for Visual Studio 2019.

When I try Debug the project, it working correctly without error but when I rebuild it, I'm getting the following error;

Object reference not set to an instance of an object

enter image description here

I don't get an error when restart Visual Studio and I can debug the project again but If I rebuild it again, I'm getting the error.

It's bundleconfig.json file

[
  {
    "outputFileName": "wwwroot/assets/css/style.bundle.min.css",
    "inputFiles": [
      "wwwroot/assets/plugins/global/plugins.bundle.css",
      "wwwroot/assets/css/style.bundle.css",
      "wwwroot/assets/css/skins/header/base/light.css",
      "wwwroot/assets/css/skins/header/menu/light.css",
      "wwwroot/assets/css/skins/brand/light.css"
    ],
    "sourceMap": false,
    "sourceMapRootPath": null
  }
,
{
  "outputFileName": "wwwroot/assets/js/scripts.min.js",
  "inputFiles": [
    "wwwroot/assets/plugins/global/plugins.bundle.js",
    "wwwroot/assets/js/scripts.js",
    "wwwroot/assets/js/pages/dashboard.js",
    "wwwroot/content/js/mobil-detect.js",
    "wwwroot/content/js/lazy-img.js",
    "wwwroot/content/js/ziyaretci.js"
  ]
}
]

enter image description here

Visual Studio, Bundler & Minifier extension, BuildBundlerMinifier and BuildBundlerMinifier.Core are up to date How can I fix it ?

like image 207
Kaan Öztürk Avatar asked Dec 10 '22 00:12

Kaan Öztürk


2 Answers

This can be an issue with the syntax in the source of one of your js files. In my case, using the nullish coalescing operator "??" was the issue. Replaced it with a simple "if" null check and the compilation error disappeared.

like image 198
user16228923 Avatar answered May 19 '23 19:05

user16228923


Solved by refactoring all "??" nullish coalescing operators with "?:" conditional (ternary) operators.

like image 28
Alexander Betser Avatar answered May 19 '23 18:05

Alexander Betser