【发布时间】:2019-05-27 13:35:57
【问题描述】:
无论我尝试什么,在使用 webpack4 构建时,我都无法将 moment.js 加载到 TypeScript 文件中。
[tsl] ERROR in /app/Repository/JFFH.Site/Resources/Private/JavaScript/Angular/schedule/schedule.component.ts(18,30)
npm_1 | TS2694: Namespace '"/app/Repository/JFFH.Site/Resources/Private/node_modules/moment/moment".export=' has no exported member 'Moment'.
我正在尝试使用的 TypeScript 文件:
import * as moment from "moment";
interface IEvent {
title: string;
startTime: string;
startTimeObject?: moment.Moment;
我的 tsconfig.json:
{
"compilerOptions": {
"outDir": "./dist/",
"noImplicitAny": true,
"module": "es6",
"target": "es5",
"jsx": "react",
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"allowJs": true
}
}
我的 Webpack4 规则:
{
test: /\.tsx?$/,
exclude: [/node_modules/, /Packages/],
use: {
loader: 'ts-loader'
}
},
{
test: /\.js$/,
exclude: [/core-js/, /@babel\/runtime/],
use: {
loader: 'babel-loader'
}
},
【问题讨论】:
标签: typescript webpack momentjs webpack-4