我知道有很多相同标题的问题,但是它们似乎没有任何合适的答案,或者与Webpack的旧版本有关。
构建(webpack --mode development
)时出现以下错误:
./ scripts / eventSchedule.ts中的错误未找到模块:错误:找不到 在'C:\ Source Control \ My Project \ scripts'中解析'./Calendar'
eventSchedule.ts文件与Calendar.ts位于同一文件夹中,并包含以下导入语句:
import * as Scheduler from "./Calendar";
Calendar.ts文件包含一个导出的类,并且在我从 Webpack 3升级到Webpack 4 之前,所有正常工作:
export class Calendar {
这些是我的webpack.config.js的内容。如何解决此错误?
请注意,虽然wwwroot/dist/
是输出目录,但是几乎所有脚本都位于scripts
中。
var path = require('path');
const webpack = require('webpack')
module.exports = {
entry: {
vendor: ['jquery', 'bootstrap', 'moment', 'fullcalendar'],
modules: [
'./scripts/Calendar.ts'
],
site: [
'./wwwroot/js/site.js',
'./scripts/onboardingFiles.ts',
'./scripts/eventFiles.ts',
'./scripts/allUsers.ts',
'./scripts/venueEquipment.ts',
'./scripts/audience.ts',
'./scripts/prerequisites.ts',
'./scripts/exportICS.ts',
'./scripts/eventSchedule.ts',
'./scripts/newHireTasks.ts',
'./scripts/upcomingEventsGrid.ts',
'./scripts/eventTypes.ts',
'./scripts/terminationTasks.ts'
]
},
output: {
path: path.join(__dirname, 'wwwroot/dist/'),
filename: '[name].bundle.js',
chunkFilename: '[name].bundle.js',
publicPath: '/',
},
optimization: {
splitChunks: {
cacheGroups: {
vendor: {
chunks: 'initial',
name: 'vendor',
test: 'vendor',
enforce: true
},
}
},
runtimeChunk: true
}
};
答案 0 :(得分:0)
我在ts-loader中遇到了同样的问题 并看着这个 https://github.com/aspnet/JavaScriptServices/issues/1562#issuecomment-371545061
我在webpack.config.js文件中注意到以下内容 对我有用
resolve: {
extensions: [".js", ".ts", ".tsx"]
},