【发布时间】:2018-05-17 07:03:36
【问题描述】:
我收到了这个错误
Uncaught TypeError: $(...).dialog is not a function
原因似乎是因为我两次导入 jquery。我找不到解决这个问题的方法。
这是我的完整错误,其中提到了引导程序。
PopupSelectCard.ts:44 Uncaught TypeError: $(...).dialog is not a function
at Object.PopupSelectCard (PopupSelectCard.ts:44)
at Object.defineProperty.value (Index.ts:21)
at __webpack_require__ (bootstrap 92cf533…:19)
at Object.defineProperty.value (bootstrap 92cf533…:62)
at bootstrap 92cf533…:62
PopupSelectCard @ PopupSelectCard.ts:44
Object.defineProperty.value @ Index.ts:21
__webpack_require__ @ bootstrap 92cf533…:19
Object.defineProperty.value @ bootstrap 92cf533…:62
(anonymous) @ bootstrap 92cf533…:62
这是我的 webpack.config.js
var debug = process.env.NODE_ENV !== "production";
var webpack = require('webpack');
module.exports = {
context: __dirname,//another dir +"/app"
// devtool: debug ? "inline-sourcemap" : null,
// Enable sourcemaps for debugging webpack's output.
devtool: "source-map",
entry: "./code/client/scripts/Index.ts",
output: {
path: __dirname + "/code/client/views",
filename: "scripts.min.js"
},
plugins: debug ? [] : [
new webpack.optimize.DedupePlugin(),
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.optimize.UglifyJsPlugin({mangle: false, sourcemap: false}),
new webpack.IgnorePlugin(/fs/),
],
node: {
fs: 'empty',
child_process: 'empty',
},
resolve: {
// Add '.ts' and '.tsx' as resolvable extensions.
alias: {
vue: 'vue/dist/vue.esm.js'
},
extensions: [".ts", ".tsx", ".js", ".json"]
},
module: {
rules: [
// All files with a '.ts' or '.tsx' extension will be handled by 'awesome-typescript-loader'.
{ test: /\.tsx?$/, loader: "awesome-typescript-loader" },
// All output '.js' files will have any sourcemaps re-processed by 'source-map-loader'.
{ enforce: "pre", test: /\.js$/, loader: "source-map-loader" }
]
},
};
这就是我在 ts 文件中导入的方式
import * as $ from "jquery";
import 'jquery-ui';
如果我不导入 jquery,我会收到编译器错误。
Cannot find name '$'.
我该如何解决这个问题?
【问题讨论】:
-
您可以在您的
webpack.config中添加jquery作为插件吗? IE。new webpack.ProvidePlugin({jQuery: 'jquery', $: 'jquery',jquery: 'jquery'}) -
@nbokmans 发生同样的问题。
-
是什么让您认为您要导入两次?如果你的 html 中有一个单独的
<script>标签来加载 jquery,请将其删除并让 webpack 处理它 -
我没有脚本。所以问题是据我了解,我有一个全局 jquery,但 webstorm 看不到它。当我导入 jquery webstorm 时可以看到它,但是这次在浏览器上运行时会出现上述错误。当我使用上述插件时,从技术上讲它应该可以工作,但它没有。这就是我感到困惑的地方。
标签: jquery typescript webpack