TypeError:jquery__WEBPACK_IMPORTED_MODULE_0 ___ default(...)(...)。typeahead不是函数

问题描述 投票:0回答:1

我刚刚通过qazxsw poi安装了qazxsw poi库。

这是我的app.js,您不需要阅读所有代码。这并不重要:

yarn install

这是我的webpack配置的一部分:

typeahead.js

不知不觉我收到了这个巨大的错误:

TypeError:jquery__WEBPACK_IMPORTED_MODULE_0 ___ default(...)(...)。typeahead不是函数

已经尝试过这个import $ from 'jquery'; import 'typeahead'; const Bloodhound = require('imports-loader?define=>false!typeahead.js/dist/bloodhound.min.js'); $(document).ready(function () { var bestPictures = new Bloodhound({ datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'), queryTokenizer: Bloodhound.tokenizers.whitespace, prefetch: 'http://twitter.github.io/typeahead.js/data/films/post_1960.json', remote: { url: 'http://twitter.github.io/typeahead.js/data/films/queries/%QUERY.json', wildcard: '%QUERY' } }); $('#custom-templates .typeahead').typeahead(null, { name: 'best-pictures', display: 'value', source: ['a'], templates: { empty: [ '<div class="empty-message">', 'unable to find any Best Picture winners that match the current query', '</div>' ].join('\n'), suggestion: function() { return '<div><strong>a</div>'; } } }); 但同样的问题。

任何帮助,将不胜感激。

webpack typeahead.js
1个回答
0
投票

这是一个导入问题,您将其作为默认导入,但此lib可能不会将自身导出为默认导出。

调查它的一种方法是检查package.json中的Encore .setOutputPath('web/' + buildFolder + '/') .setPublicPath('/' + buildFolder) .addEntry('app', './assets/js/app.js') .autoProvidejQuery() .enableSourceMaps(!Encore.isProduction()) .enableVersioning(Encore.isProduction()) .enableSassLoader() .enablePostCssLoader() .addPlugin(new CopyWebpackPlugin([ {from: 'assets/img', to: './img'}, ])).autoProvideVariables({ $: 'jquery', jQuery: 'jquery', 'window.jQuery': 'jquery' }) 字段是什么,然后按照指定跟随solution文件,并看到它使用main模块定义,如果你使用dist/typeahead.bundle.js语法,你将使用UMD import/export

这意味着您需要使用导入此lib

module.exports = factory(require("jquery"));

你将获得line lib的实例。

看起来这个特定的lib在github中有这个问题,这就解决了它。 import * as typehaed from 'typeahead'

© www.soinside.com 2019 - 2024. All rights reserved.