0

I am using ASP.NET MVC and I have a javascript file in ~Scripts/bundle/build.js. The file is generated with webpack, which renders a bunch of ES6 javascript files in Scripts. I am loading bundle.js first and then calling the function in a different script like this:

// @Scripts.Render("~/bundles/Webpack")
<script src="~/Scripts/build/bundle.js"></script>
<script>
    connectToVnc();
</script>

(first line is commented, I have tried loading the script using bundles in BundleConfig.cs).

I get the error connectToVnc is not defined, even though it is defined in bundle.js.

What am I doing wrong?

13
  • Is your bundle.js script successfully loaded in the browser? Check the browser's debugging tools to find out. Commented Oct 27, 2017 at 11:22
  • Does connectToVnc work in your console? Commented Oct 27, 2017 at 11:22
  • Webpack only loads the files as they are needed so although your function is in bundle.js, it may not have been loaded yet. You should be placing the function call in the correct script that is loaded by webpack Commented Oct 27, 2017 at 11:23
  • @David I can locate the script in "Sources" (Chrome). Commented Oct 27, 2017 at 11:29
  • @aaron no, that does not work either. Commented Oct 27, 2017 at 11:31

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.