3

I'm using Angular2, and I'd like to include jQuery.

systemjs.config.js

(function (global) {
 System.config({
 paths: {
  'npm:': 'node_modules/',
  'jquery': "//code.jquery.com/jquery-2.1.4.min.js"
 },
 meta: {
    bootstrap: {
        deps: ['jquery']
    }
 },
.....
}

In app.module.ts, I got the error : Cannot find the module 'jquery' when I put :

import $ from 'jquery';

I try it using map instead of paths, but the same result..

6
  • TypeScript looks for packages into node_modules directory by default. Did you install jQuery with npm? Commented Oct 25, 2016 at 9:22
  • I already have jquery in /dev/assets/js folder not in node_modules Commented Oct 25, 2016 at 9:24
  • That's why it doesn't work, TypeScript can find jquery and throws an error. With jquery it's actually more complicated and you need to install also its typings. If you're using TypeScript 2.0 you can use npmjs.com/package/@types/jquery Commented Oct 25, 2016 at 9:38
  • I've downloaded it, the package.json was updated but the same problem (nothing's changed) :/ Commented Oct 25, 2016 at 11:24
  • What's your TypeScript version? Commented Oct 25, 2016 at 11:31

1 Answer 1

2

The correct code is:

import * as $ from 'jQuery';

Also should you be mapping to a CDN?

Why not get jQuery via NodeJS or save jQuery locally and map to it?

Sign up to request clarification or add additional context in comments.

2 Comments

because I bought a template, and I have a lot of jQuery plugins... (I used the jQuery link just to make sure of path)
Actually, for SystemJS, and for compliance with ECMAScript, the correct code is import $ from 'jquery'; Callable module namespace objects are not supported by the spec and are largely a CommonJS interop hack provided by TypeScript.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.