Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Once minified, my site is no longer working #7

Open
SoftCircuits opened this issue Jun 15, 2022 · 12 comments
Open

Once minified, my site is no longer working #7

SoftCircuits opened this issue Jun 15, 2022 · 12 comments

Comments

@SoftCircuits
Copy link

SoftCircuits commented Jun 15, 2022

Installed product versions

  • Visual Studio: 2022 Community
  • This extension: 2.9.3

Description

Am I the only one experiencing my code not working after it's minified?

Steps to recreate

My site was working fine. Then I enabled minification and I'm getting all sorts of JavaScript errors.

It's not JavaScript that I wrote. So it might be beyond my abilities to actually debug the code so I can tell you what's missing. I was just wondering if this is a known issue. Doesn't it rearrange things in some cases? Anything you can suggest?

UPDATE:

I'm not sure if this is helpful but I'm attaching three files.

File Description
chart.min.js Chart.js (already minified)
charts.js My own JavaScript file
charts.min.js The resulting minified file

Notes:

  • chart.min.js is included before charts.js and listed in the same order in bundleconfig.json.
  • When I include the first two files, I get no JavaScript errors.
  • When I include the minified files, I get the following errors:
Uncaught RangeError: minimumFractionDigits value is out of range.
    at new NumberFormat (<anonymous>)
    at charts.min.js:7:21574
    at ir (charts.min.js:7:21616)
    at uh.numeric (charts.min.js:14:30634)
    at o (charts.min.js:7:5694)
    at uh.generateTickLabels (charts.min.js:14:36473)
    at uh._convertTicksToLabels (charts.min.js:14:39520)
    at uh.update (charts.min.js:14:34888)
    at gr (charts.min.js:7:29604)
    at Object.update (charts.min.js:14:14072)

charts.min.js:7

Uncaught ReferenceError: Cannot access 'l' before initialization
    at tv (charts.min.js:7:32917)
    at lf.parse (charts.min.js:14:22987)
    at lf._insertElements (charts.min.js:14:28826)
    at lf._resyncElements (charts.min.js:14:28549)
    at lf.buildOrUpdateElements (charts.min.js:14:22282)
    at l.update (charts.min.js:14:61232)
    at new l (charts.min.js:14:57449)
    at Object.<anonymous> (charts.min.js:7:754)
    at c (vendor.min.js:1:27602)
    at Object.fireWith [as resolveWith] (vendor.min.js:1:28346)

charts.min.js:7

JavaScript.zip

@SoftCircuits SoftCircuits changed the title One minified, site is no longer working Once minified, my site is no longer working Jun 15, 2022
@failwyn
Copy link
Owner

failwyn commented Jun 18, 2022

If you can post a sample project with those files, I’ll try to debug it for you, I’m bundling and minimizing almost 200 files in my project, so it could be a wuirk with the library you are using; I’ll do my best to address it.

@SoftCircuits
Copy link
Author

@failwyn What would you like to see? Do you mean a working website?

@failwyn
Copy link
Owner

failwyn commented Jun 18, 2022

Doesn’t have to be working, I just need enough to replicate your error so that I can debug it.

@SoftCircuits
Copy link
Author

@failwyn Ok, this was a little tricky as my JavaScript was making AJAX calls but I was able to duplicate the issue without modifying the original files.

In index.htm, you'll find the following block of code.

<!-- Minified and bundled files -- DOES NOT WORK -->
<!-- <script src="charts.min.js"></script> -->

<!-- Unminified and bundled files -- WORK FINE -->
<script src="chart.min.js"></script>
<script src="charts.js"></script>

As it stands, the code includes chart.min.js and charts.js, and there are no errors. But if you comment out those two lines and instead include the minified and bundled file charts.min.js, there are errors.

The two versions should work exactly the same.

Test.zip

@failwyn
Copy link
Owner

failwyn commented Jun 18, 2022

@SoftCircuits I need to be able to replicate the issue with Bunder & Minifier so I would need the bundleconfig.json file. One thing I thought of, are you minimizing the already minimized chart.min.js file? Do you have access to chart.js? If you Bundle chart.js and charts.js, then enable minification, it will probably work. I've never tried minimizing a minimized file, but I imagine it could definitely be the source of your issue.

@SoftCircuits
Copy link
Author

SoftCircuits commented Jun 18, 2022

@failwyn Yes, I am minimizing an already minimized file. I think this should be supported, much like zipping an already zipped file is supported.

I would have to search to see if the unminified version is available. I just used the one I had. If you tell me I can't minify a minified file, then that's what I would try to do. But my opinion is that the software should handle this.

Is there a way to tell bundleconfig.json to bundle files without minifying them?

My bundleconfig.json is below, but only the last entry is related to the files I sent you.

[
  {
    "outputFileName": "wwwroot/bundles/site.min.css",
    "inputFiles": [
      "wwwroot/lib/bootstrap/dist/css/bootstrap.css",
      "wwwroot/css/site.css"
    ]
  },
  {
    "outputFileName": "wwwroot/bundles/site.min.js",
    "inputFiles": [
      "wwwroot/lib/jquery/dist/jquery.min.js",
      "wwwroot/lib/bootstrap/dist/js/bootstrap.bundle.min.js",
      "wwwroot/js/site.js"
    ]
  },
  {
    "outputFileName": "wwwroot/bundles/layout.min.css",
    "inputFiles": [
      "wwwroot/layout/css/app.css",
      "wwwroot/layout/css/style.css"
    ]
  },
  {
    "outputFileName": "wwwroot/bundles/layout.min.js",
    "inputFiles": [
      "wwwroot/layout/js/vendor.js",
      "wwwroot/layout/js/app.js"
    ]
  },
  {
    "outputFileName": "wwwroot/bundles/charts.min.js",
    "inputFiles": [
      "wwwroot/lib/chart.js/chart.min.js",
      "wwwroot/js/charts.js"
    ]
  }
]

@failwyn
Copy link
Owner

failwyn commented Jun 18, 2022

I'm not sure that's the issue, it was just a guess, try this and see if you still get the same error; if it works, then it could be an issue with NUglify.

}
"outputFileName": "wwwroot/bundles/charts.min.js",
"inputFiles": [
"wwwroot/lib/chart.js/chart.min.js",
"wwwroot/js/charts.js"
],
"minify": {
"enabled": false
}
}

@SoftCircuits
Copy link
Author

@failwyn Yes, that appears to be working.

@SoftCircuits
Copy link
Author

@failwyn Thanks for looking into. As stated previously, I think this should be supported. If it were my software, I'd make sure it handled minifying an already minified file. But now I know the issue, I'll be able to move forward. Thanks again.

BTW, what are the rules about when the minified and bundled files are produced? Sometimes I make changes and they build right away. And other times it takes me considerable time to get it to rebuild them.

@failwyn
Copy link
Owner

failwyn commented Jun 18, 2022

Bundler & Minifier uses NUglify to minimize the files, you could try posting an issue on their GitHub repository to see if the contributors have a better answer; if they fix it, I’ll definitely upgrade the version used in the extension.

It should update the bundle whenever any of the inout files are modified; I have bundles that contain over 100 input files and I’ve never had an issue with it not updating. If you can provide steps to reproduce the issue, I’d be happy to look at it.

@SoftCircuits
Copy link
Author

SoftCircuits commented Jun 18, 2022

@failwyn Looks like it's not creating one of my files due to an error.

System.NullReferenceException: Object reference not set to an instance of an object.
at BundlerMinifier.BundleFileProcessor.Process(String fileName, IEnumerable`1 bundles) in W:\Git\Light Speed Solutions\BundlerMinifier\src\BundlerMinifier.Core\Bundle\BundleFileProcessor.cs:line 38
at BundlerMinifierVsix.BundleService.<>c__DisplayClass8_0.b__0(Object o) in W:\Git\Light Speed Solutions\BundlerMinifier\src\BundlerMinifierVsix\BundleService.cs:line 112

I probably have something wrong in my config file but haven't found it yet.

UPDATE:

It appears the problem is with processing the file chart.js. If I comment out that file from the bundle, it builds the output file.

Description Project File Line
(Bundler & Minifier) Strict-mode does not allow duplicate property names: = charts.min.js 1840
(Bundler & Minifier) Strict-mode does not allow duplicate property names: = charts.min.js 1840
(Bundler & Minifier) Implicit property name must be identifier: stackWeight = charts.min.js 3015
(Bundler & Minifier) Strict-mode does not allow duplicate property names: = charts.min.js 4252
(Bundler & Minifier) Strict-mode does not allow duplicate property names: = charts.min.js 7702
(Bundler & Minifier) Strict-mode does not allow duplicate property names: = charts.min.js 9865
(Bundler & Minifier) Strict-mode does not allow duplicate property names: = charts.min.js 10163
(Bundler & Minifier) Strict-mode does not allow duplicate property names: = charts.min.js 10329

@failwyn
Copy link
Owner

failwyn commented Jul 18, 2024

If you can isolate the code that is causing the error I can try to fix it in NUglify

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants