我從webpack收到以下錯誤。typescript:使用typescript和webpack解析typeahead.js 2
ERROR in ./wwwroot/js/admin/infrastructure/typeaheadComponent.ts Module not found: Error: Can't resolve 'typeahead' in ...
我有以下安裝
npm install typeahead.js
npm install @types/typeahead
我的打字稿如下所示,使用node
模塊分辨率。
import { module } from "angular";
import "typeahead";
// necessary to import typeahead into JQuery, as otherwise
// typeahead below is not defined.
class TypeAheadController {
foo(e) {
$(e).typeahead(...)
}
}
這個如下生成JavaScript:
"use strict";
var angular_1 = require("angular");
require("typeahead");
var TypeAheadController = (function() { ...
我webpack.config.js如下:
module.exports = {
context: __dirname,
entry: [
"./app.ts",
"./tab.ts",
"./client/clientService.ts",
"./client/clientSearchComponent.ts",
"./infrastructure/messageComponent.ts",
"./infrastructure/typeaheadComponent.ts",
"./url.ts"],
output: {
filename: "./wwwroot/js/admin/admin.js"
},
devtool: "source-map",
module: {
rules: [
{ test: /\.ts$/, use: 'ts-loader' }
]
}
};
導入一飲而盡任務。
如何指定typeahead
位於node_modules/typeahead.js/dist/typeahead.bundle.js
它解決了部分問題,typeahead.js文件在被組件使用後包含在輸出中,因此整個導入仍然被破壞,並且需要我手動包含typeahead.js文件。 – Jim