gpt4 book ai didi

typescript - 无法重新声明 block 作用域变量 'jQuery'

转载 作者:搜寻专家 更新时间:2023-10-30 21:12:08 24 4
gpt4 key购买 nike

问题

如何阻止 VS Codedeclare var jQuery:any; 显示为错误?

更多信息

vs code cannot redeclare block-scoped variable 'jQuery'

我做了什么

快速搜索后,我找到了一个建议 this ,这表明 jQuery 变量已经在同一代码块的其他地方定义。所以我删除了这个引用。 VS Code 停止提示,但控制台显示以下错误,我的应用程序无法编译。

ERROR in src/app/app.config.ts(34,25): error TS2304: Cannot find name 'jQuery'. src/app/pages/pages.component.ts(31,27): error TS2304: Cannot find name 'jQuery'.

所以我重新添加了我刚刚删除的行并且我的应用程序符合要求但是我在浏览器中收到以下错误(在开发工具控制台中)

ERROR Error: Uncaught (in promise): TypeError: __webpack_require__.e is not a function
TypeError: __webpack_require__.e is not a function
at webpackAsyncContext (eval at ./src/$$_lazy_route_resource lazy recursive (main.bundle.js:13), <anonymous>:11:29)
at SystemJsNgModuleLoader.loadAndCompile (core.js:6554)
at SystemJsNgModuleLoader.load (core.js:6538)
at RouterConfigLoader.loadModuleFactory (router.js:4543)
at RouterConfigLoader.load (router.js:4523)
at MergeMapSubscriber.eval [as project] (router.js:2015)
at MergeMapSubscriber._tryNext (mergeMap.js:128)
at MergeMapSubscriber._next (mergeMap.js:118)
at MergeMapSubscriber.Subscriber.next (Subscriber.js:92)
at ScalarObservable._subscribe (ScalarObservable.js:51)
at webpackAsyncContext (eval at ./src/$$_lazy_route_resource lazy recursive (main.bundle.js:13), <anonymous>:11:29)
at SystemJsNgModuleLoader.loadAndCompile (core.js:6554)
at SystemJsNgModuleLoader.load (core.js:6538)
at RouterConfigLoader.loadModuleFactory (router.js:4543)
at RouterConfigLoader.load (router.js:4523)
at MergeMapSubscriber.eval [as project] (router.js:2015)
at MergeMapSubscriber._tryNext (mergeMap.js:128)
at MergeMapSubscriber._next (mergeMap.js:118)
at MergeMapSubscriber.Subscriber.next (Subscriber.js:92)
at ScalarObservable._subscribe (ScalarObservable.js:51)
at resolvePromise (zone.js:809)
at resolvePromise (zone.js:775)
at eval (zone.js:858)
at ZoneDelegate.invokeTask (zone.js:421)
at Object.onInvokeTask (core.js:4736)
at ZoneDelegate.invokeTask (zone.js:420)
at Zone.runTask (zone.js:188)
at drainMicroTaskQueue (zone.js:595)
at <anonymous>

所以我终止了应用程序并重新启动它。现在应用程序运行没有错误,但 VS Code 再次显示同样的问题。

tsconfig.json

{
"compileOnSave": false,
"compilerOptions": {
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2017",
"dom"
]
}
}

最佳答案

以下步骤可能会解决您的问题。让我知道您的意见。


1.) 从 npm 安装 jquery 类型和 jquery

npm install jquery
npm install @types/jquery

2.) 将 jquery 添加到 .angular-cli.json

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

3.) 在您的 pages.component.ts 文件中声明。

declare let $: any;
declare let jQuery: any;

关于typescript - 无法重新声明 block 作用域变量 'jQuery',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49395050/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com