Currently, I am working on a Typescript application in Visual Studio 2015 where RequireJS is used for loading modules.
I have successfully loaded various modules from .ts classes and external libraries by using their typing .d.ts files. However, I have encountered an issue when attempting to load a jQuery plugin.
While I am utilizing the typing file for the library, there are no module definitions present in the .d.ts file since it is simply a plugin for jQuery.
In order to address this issue, I have followed the guidelines for shim library loading as recommended on the RequireJS website.
requirejs.config({
baseUrl: "Scripts",
paths: {
"jquery": "jquery-2.2.3",
"jquery.pjax": "jquery.pjax"
},
shim:
{
"jquery.pjax":
{
deps: ["jquery"],
exports: "jQuery.fn.pjax"
}
}
});
require(["app"]);
As per the RequireJS website:
The shim config only establishes code relationships. To load modules that are part of or use shim config, a regular require/define call is required. Setting up the shim alone does not trigger code loading.
Despite trying multiple approaches (including moving the jquery.pjax.d.t file next to the jquery.pjax.js), none of them seem to work when it comes to loading the plugin:
import * as pjax from "jquery.pjax";
import pjax = require("jquery.pjax");
import pjax = require("./jquery.pjax");
import pjax = require("jquery.pjax.js");
import pjax = require("./jquery.pjax.js");
The compiler throws errors such as Cannot find module "jquery.pjax"
or
File C:/foo/bar/jquery.pjax.d.ts is not a module
.
The app.ts file fails to compile with any of the aforementioned codes present, and removing them prevents the plugin from being loaded.
Considering the fact that I use multiple imports in my app.ts file and anticipate more in the future, I prefer utilizing the import Foo = require("foo")
or import * as Foo from "foo"
module loading styles rather than manually writing the AMD define function.
In addition, I rely on Nuget package management and would rather not manually edit or move external .d.ts or .js files.
If anyone could provide assistance in resolving this issue, I would greatly appreciate it.