【问题标题】:jQuery.validator webpack 2 and typescriptjQuery.validator webpack 2 和打字稿
【发布时间】:2017-10-24 01:03:34
【问题描述】:

我正在尝试使用 webpack 2 设置我的项目的脚本。

目前我的文件正在编译,但 jQuery-validation

有问题

当我尝试生成我的文件时出现此错误:

./wwwroot/scripts/ts/core.ts (18,20) 中的错误:错误 TS2339:属性 'validator' 在类型 'JQueryStatic' 上不存在。

这是我在 core.ts 中的导入:

import jQuery = require("jquery");
import "jquery-validation"

还有我的 webpack 配置:

'use strict';

var webpack = require('webpack');
var path = require('path');

module.exports = {
    cache: true,
    entry: {
        main: './wwwroot/scripts/ts/public/index.ts'
    },
    output: {
        path: path.resolve(__dirname, './wwwroot/scripts/js'),
        filename: '[name].js',
    },
    plugins: [
        new webpack.ProvidePlugin({
            jQuery: 'jquery',
            $: 'jquery',
            jquery: 'jquery'
        })
    ],
    module: {
        loaders: [{
            test: /\.ts$/,
            exclude: /node_modules/,
            loader: 'ts-loader'
        }, {
            test: /\.js$/,
            exclude: /node_modules/,

        }]

    },
    resolve: {
        extensions: ['.ts', '.tsx', '.js']

    }
};

我已经在 Google 上找到了很多东西,但任何解决方案都适合我,所以如果有人有想法...

【问题讨论】:

    标签: jquery typescript webpack


    【解决方案1】:

    您必须为jquery-validation 安装类型:

    npm install --save-dev @types/jquery.validation
    

    【讨论】:

    • 当然是安装了,不是jquery.validation而是jquery-validation
    • @OrcusZ。 @types/jquery.validation 是包含 jquery-validation 库的类型的包。见this。并且没有名称为 jquery-validation 的类型。你安装了什么类型的包?
    • 对不起,我和 npm 包混淆了。我安装的类型(在@types 文件夹下)是:jquery、jquery-validation-unobtrusive、jquery.validation
    • @OrcusZ 如果您安装了这些类型,请发布一个可重现的示例。一个plunkr会有所帮助。到目前为止,很难看出哪里出了问题。
    • 该死...我应该在我的打字稿文件中导入 jquery-calidation 而不是 jquery.validation
    猜你喜欢
    • 2016-02-06
    • 2017-09-26
    • 2016-10-27
    • 2021-02-10
    • 1970-01-01
    • 2016-04-23
    • 1970-01-01
    • 2017-05-02
    • 2020-11-22
    相关资源
    最近更新 更多