admin管理员组文章数量:1432001
I am using libman.json to pull client side libraries from cdnjs into a folder in my project. I then want to bundle and minify those libraries into a single js file that will be deployed and referenced in the web app. To do this I am using a visual studio extension called Bundler & Minifier. I have everything all set up in my bundle.config but I have run into a problem with one of the libraries I am trying to bundle. Specifically, if I try to include Chart.js (2.8.0) in the bundle I get the following error on build:
(Bundler & Minifer) Strict-mode does not allow assignment to undefined variables: r
Shouldn't this be a warning and not an error? I don't see how this should prevent bundling/minification and cause the build to fail. Is there a way to override this behavior?
I am using libman.json to pull client side libraries from cdnjs into a folder in my project. I then want to bundle and minify those libraries into a single js file that will be deployed and referenced in the web app. To do this I am using a visual studio extension called Bundler & Minifier. I have everything all set up in my bundle.config but I have run into a problem with one of the libraries I am trying to bundle. Specifically, if I try to include Chart.js (2.8.0) in the bundle I get the following error on build:
(Bundler & Minifer) Strict-mode does not allow assignment to undefined variables: r
Shouldn't this be a warning and not an error? I don't see how this should prevent bundling/minification and cause the build to fail. Is there a way to override this behavior?
Share Improve this question asked May 14, 2019 at 23:38 Nathan KamenarNathan Kamenar 90411 silver badges35 bronze badges 6-
I don't think that's really a bundling error... the .js file is using strict-mode. When in strict mode, .js should explicitly define variables... (cannot use undefined variables)... just fix the error in the .js file (use
var
to define the variable) or remove the"use strict";
– Hooman Bahreini Commented May 15, 2019 at 1:36 - I agree but the problem there is that I shouldn't be modifying third party libraries that I am getting through a package manager because then everyone on my team needs to make sure they make the same modifications. I agree that it is the Chart.js developers fault for putting 'use strict' in their source and then not obeying all the rules but I would still argue that this shouldn't prevent minification and bundling. A warning should be printed for sure but it should not prevent me from building my solution. – Nathan Kamenar Commented May 15, 2019 at 1:49
- The problem is with Chart.js. If you look at the source in the link below on lines 359-364 you will see case statements that set a variable r without r ever being declared. That is what is causing the bundler to fail. cdnjs.cloudflare./ajax/libs/Chart.js/2.8.0/Chart.bundle.js – Nathan Kamenar Commented May 15, 2019 at 2:14
- Maybe raise the issue/bug on their github... – Hooman Bahreini Commented May 15, 2019 at 2:24
- I will do that but I was hoping for a workaround in the meantime because this is literally preventing me from building our solution. – Nathan Kamenar Commented May 15, 2019 at 2:26
2 Answers
Reset to default 3The undefined variables assignment issue was raised in Chart.js GitHub on March 18, 2019.
For fixing it manually, add the following variables declaration in Chart.js hwb2rgb(hwb)
function (line 343, v2.8.0):
var r, g, b;
Shouldn't this be a warning and not an error?
No, because that's the whole point of using strict mode, we want to get error (not warning). From mozilla developer refernce
Strict mode changes some previously-accepted mistakes into errors. JavaScript was designed to be easy for novice developers, and sometimes it gives operations which should be errors non-error semantics. Sometimes this fixes the immediate problem, but sometimes this creates worse problems in the future. Strict mode treats these mistakes as errors so that they're discovered and promptly fixed.
If your third party library has an error, you can either fix the problem or ditch the library... if you don't want to fix it in your local project, you can raise an issue here
本文标签: javascriptBundler amp Minifier failing because of using strictStack Overflow
版权声明:本文标题:javascript - Bundler & Minifier failing because of using strict - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745544827a2662657.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论