0

I want to import jQuery in an Angular 5 project using TypeScript 2.8.1. I follow Ervin Llojku solution but this does not the trick :

Install jquery with npm

npm install --save jquery

Install jquery with npm

npm install --save-dev @types/jquery

Add scripts to .angular-cli.json

"apps": [{
  ...
  "scripts": [
    "../node_modules/jquery/dist/jquery.min.js",
  ],
  ...
}]

I also try to add these imports in app.module.ts or in component :

import * as $ 'jquery';

Whatever I try TypeScript compiler throws this error :

Error:(7, 15) TS2497: Module ''jquery'' resolves to a non-module entity and cannot be imported using this construct.

1 Answer 1

0

I have followed another answer and I replaced

import * as $ 'jquery';

with

import 'jquery';

in app.module.ts and everything seems to be OK.

Still I don't know if this error was due to Angular 5 or TypeScript 2.8.1...

or maybe to the tsconfig.json generated by Angular :

"compilerOptions": {
  "moduleResolution": "node",
}
Sign up to request clarification or add additional context in comments.

Comments

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.