cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
New Member

jquery in typescript file in subfolder

In index.ts I import a typescript file (import {Dropdown} from "../../../../<folder>/<file>)

This imported ts file has an import of jquery defined: import * as $ from 'jquery'

When building, I get an error that module jquery cannot be found.

I also added this import in index.ts as that is where external libraries are imported.

But I still get the same issue.

As a test, I created a ts file on same level as the index.ts file and copied the content of the imported file.

When I use this new file, all works fine.
However according to the guidelines, I am supposed to use the import (shared code over multiple projects).
I don't find a solution for the jquery error.
Has someone a suggestion?

I used the latest version of the CLI to create PCF project.

1 ACCEPTED SOLUTION

Accepted Solutions

The shared DropDown was created by a colleague who has left the team.
To solve the issue I have removed the node_modules in the DropDown folder, and re-installed jquery (and only jquery).
That seems to fix the issue. 

(I should have thought about trying this trick earlier).

 

I'll document it for the person(s) who will have to take over after my leave.

View solution in original post

3 REPLIES 3
Solution Sage
Solution Sage

Your best approach is probably to install the jquery typescript declaration file and see if that resolves the issue. So in the directory the project is in run

 

npm install --save jquery

and 

 

 

npm install --save-dev @types/jquery

 

 

 

And to reference it in the project do the following.

 

import $ from "jquery";
// or
import $ = require("jquery");

You may also need to include with --allowSyntheticDefaultImports—add "allowSyntheticDefaultImports": true in tsconfig.json but I don't know if that is essential or just something from years ago.

 

---
If this post has answered your question please consider it for "Accept as Solution" or if it has been helpful give it a "Thumbs Up".

I already tried this: doesn't solve the issue unfortunately.

The shared DropDown was created by a colleague who has left the team.
To solve the issue I have removed the node_modules in the DropDown folder, and re-installed jquery (and only jquery).
That seems to fix the issue. 

(I should have thought about trying this trick earlier).

 

I'll document it for the person(s) who will have to take over after my leave.

View solution in original post

Helpful resources

Announcements
New Badges

New Solution Badges!

Check out our new profile badges recognizing authored solutions!

New Power Super Users

Congratulations!

We are excited to announce the Power Apps Super Users!

Power Apps Community Call

Power Apps Community Call: February

Did you miss the call? Check out the Power Apps Community Call here.

Users online (39,433)