I'm attempting to use jQuery within my project.
Within the package.json file, it has
"devDependencies": {
"@types/webpack-env": "^1.13.0",
"aspnet-webpack": "^2.0.1",
"awesome-typescript-loader": "^3.0.0",
"bootstrap": "^3.3.6",
"css-loader": "^0.25.0",
"event-source-polyfill": "^0.0.7",
"extract-text-webpack-plugin": "^2.0.0-rc",
"file-loader": "^0.9.0",
"isomorphic-fetch": "^2.2.1",
"jquery": "^3.2.1",
"style-loader": "^0.13.1",
"typescript": "^2.2.1",
"url-loader": "^0.5.7",
"vue": "^2.2.2",
"vue-loader": "^11.1.4",
"vue-property-decorator": "^5.0.1",
"vue-router": "^2.3.0",
"vue-template-compiler": "^2.2.2",
"webpack": "^2.2.0",
"webpack-hot-middleware": "^2.12.2"
}
And within the ProjectName.Web.csproj:
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.3" />
<PackageReference Include="jQuery" Version="3.2.1" />
</ItemGroup>
I installed Install jQuery and its type definitions using npm install --save jquery @types/jquery. I then attempt to import jQuery into my Typescript file using import * as $ from 'jquery'; That produces an error:
Could not find a declaration file for module 'jquery'. {project_path}/node_modules/jquery/dist/jquery.js' implicitly has an 'any' type.
What setting am I missing in order to use jQuery for this template?
I finally was able to get jQuery working in my project.
I updated my code using the example here
I also needed to run npm install @types/jquery for my project.
After those two steps and using the import * as $ from 'jquery'; statement, I received the error:
ERROR in [at-loader] ./node_modules/@types/jquery/index.d.ts:2961:63
TS2304: Cannot find name 'Iterable'.
With searching online, I found that changing
"target": "es5"
to
"target": "es6"
Within the tsconfig.json file removed the error.
Most helpful comment
I finally was able to get jQuery working in my project.
I updated my code using the example here
I also needed to run
npm install @types/jqueryfor my project.After those two steps and using the
import * as $ from 'jquery';statement, I received the error:ERROR in [at-loader] ./node_modules/@types/jquery/index.d.ts:2961:63 TS2304: Cannot find name 'Iterable'.With searching online, I found that changing
to
Within the
tsconfig.jsonfile removed the error.