无论我如何尝试,使用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'
}
},
答案 0 :(得分:0)
ts-loader
似乎是一个问题。
正如我发现的那样,由于babel-loader
现在可以理解打字稿,因此可以省略它。