【问题标题】:Use moment.js with ts-loader in webpack 4在 webpack 4 中使用 moment.js 和 ts-loader
【发布时间】: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


    【解决方案1】:

    ts-loader 似乎有问题。

    我发现它可以省略,因为 babel-loader 现在可以理解 typescript,它可以工作。

    【讨论】:

      猜你喜欢
      • 2017-05-27
      • 2021-05-05
      • 2018-09-19
      • 1970-01-01
      • 2019-05-04
      • 2016-06-29
      • 2017-08-21
      • 2019-08-25
      • 2016-06-03
      相关资源
      最近更新 更多