cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
binau_Rd
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
ben-thompson
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
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

PowerPlatform 768x460.png

Microsoft Learn

Check out our new Discover Your Career Path blog post series and get all the details.

Users online (1,116)