gpt4 book ai didi

javascript - 导入 Typescript 时找不到 Webpack 模块

转载 作者:行者123 更新时间:2023-12-01 03:50:57 25 4
gpt4 key购买 nike

我目前正在转换一个项目以使用 Webpack 进行捆绑。

在我的 Typescript 文件中,我按如下方式导入模块,并且没有收到任何错误以及智能感知。

import * as $ from "jquery";
import * as CrudHelper from "../../ts-helpers/crud-helper";
import { ExportToExcel } from "../../ts-helpers/export-helper";
import { getParameterByName } from "../../ts-helpers/utils";

这是与 webpack 一起使用的,但事实证明,由 Visual Studio 创建的转译 JS 文件仍然存在,并且我已经关闭了 TypeScript 编译。

删除 js 文件后,当我运行 webpack.config 时,出现模块未找到错误,例如

Module not found: Error: Can't resolve '../../ts-helpers/crud-helper' in 'C:\Users\alexl\git\eServicesWebpack\eServices\src\eServices.Web\Client\ts\Areas\Employee'
@ ./Client/ts/Areas/Employee/Absence.ts 4:17-56
@ multi ./Client/ts/Areas/Employee/Absence.ts

我的tsconfig看起来像

{
"compilerOptions": {
"noImplicitAny": false,
"noEmitOnError": true,
"removeComments": false,
"sourceMap": true,
"target": "es5",
"allowJs": true
},
"exclude": [
"node_modules",
"wwwroot",
"typings"
]
}

我的 tsconfig 中是否缺少某些内容?

编辑

这是我的webpack.config

var webpack = require('webpack');
var path = require('path');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var glob = require('glob');

var files = glob.sync("./Client/ts/Areas/**/*.ts");

var entry = {
'vendor': "./Client/ts/Vendor.ts"
}

files.forEach(function (e) {
var split = e.split('/');
var entryName = "";
if (split[5].indexOf('Modal') > -1) {
entryName = split[4] + '/' + split[5].split('.')[0].replace('Modal', '') + '/' + split[5].split('.')[0];
} else {
entryName = split[4] + '/' + split[5].split('.')[0].replace('Modal', '') + '/' + split[5].split('.')[0].replace('Modal', '');
}

if (entry[entryName] === undefined) {
entry[entryName] = [];
}
entry[entryName].push(e);
});

module.exports = function () {
return {
entry: entry,
output: {
path: path.resolve(__dirname, "../wwwroot/dist"),
filename: "[name].bundle.js"
},
plugins: [
//chunk vendor code into own bundle
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
minChunks: function (module) {
return module.context && module.context.indexOf('node_modules') !== -1;
}
}),
//chunk webpack runtime code co vendor code can be cached
new webpack.optimize.CommonsChunkPlugin({
name: 'manifest'
}),
new ExtractTextPlugin('styles.css'),
//protect against old libraries that reference jquery symbols
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery"
})
],
module: {
rules: [
{
test: /\.css$/,
use: ExtractTextPlugin.extract({
use: 'css-loader'
})
},
{
test: /\.ts$/,
use: "awesome-typescript-loader"
},
{
test: /\.(jpg|png|gif)$/,
use: 'file-loader'
}, {
test: /\.(woff|woff2|eot|ttf|svg)$/,
use: {
loader: 'url-loader',
options: {
limit: 100000
}
}
}
]
}
}
};

最佳答案

添加“.ts”作为可解析的扩展名。

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

关于javascript - 导入 Typescript 时找不到 Webpack 模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43205389/

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