【问题标题】:TypeScript typings broken (error TS2687): All declarations of 'iterator' must have identical modifiersTypeScript 分型损坏(错误 TS2687):“迭代器”的所有声明必须具有相同的修饰符
【发布时间】:2017-08-13 00:59:07
【问题描述】:

在将路由器包添加到我的 Angular 应用程序(需要升级 Core、Common、Compiler 等)后,我在正确输入时遇到问题。

在谷歌上搜索特定错误代码导致我遇到许多问题,主要解决方法是删除 node_modulestypings 并重新创建它们。我已经这样做了,但遇到了同样的不当行为。

在 SO 上,有 another question,但它很旧,与大多数软件包的不同版本有关,我几乎看不出它与我的问题有何关系。

坦率地说,我有点迷茫,因为我根本不知道如何解决它。下面是我的 tsconfig.json,如果它有助于发现一些奇怪的东西。

编辑

const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");

const distribution = path.resolve(__dirname, "distribution");
const application = path.resolve(__dirname, "source/application");
const resources = path.resolve(__dirname, "source/resources");

module.exports = {
  entry: "./source/application/main.ts",
  output: {
    path: distribution,
    filename: "bundle.js"
  },
  module: {
    loaders: [
      { test: /\.png$/, loader: "raw-loader", include: [resources] },
      { test: /\.s(a|c)ss$/, loaders: ["raw-loader", "sass-loader"] },
      { test: /\.html$/, loader: "raw-loader", include: [application] },
      { test: /\.ts$/, loader: "ts-loader", include: [application] },
    ]
  },

  resolve: {
    modules: ["node_modules", application],
    extensions: [".js", ".ts"]
  },

  performance: {},
  devtool: "source-map",
  context: __dirname,
  target: "web",
  externals: [],
  stats: {},

  devServer: {
    contentBase: distribution,
    port: 3002
  },

  plugins: [
    new HtmlWebpackPlugin({ template: "./source/index.html" }),
    new CopyWebpackPlugin([{ from: "./source/resources", to: "resources" }])
  ]
}

【问题讨论】:

  • 在外部 Web 工具 C:\Program Files\nodejs 中添加路径
  • @VenkateswaranR 请问我在哪里设置呢?我该怎么设置它?
  • 在 Visual Studio 工具栏 Tools-->Options-->Projects&Solutions--->External Web Tools and C:\Program Files\nodejs 并设置为 first
  • @VenkateswaranR 嗯...我在 VS Code 上,即根本不是 Visual Studio...
  • 你在用webpack吗,能不能说一下typescript版本

标签: node.js angular typescript typescript-typings


【解决方案1】:

在 Webpack.common.js 中删除 debug=true 行,并更改以下代码

module.exports = {
    entry: {
        'polyfills': './src/polyfills.ts',
        'vendor': './src/vendor.ts',
        'app': './src/main.ts'
    },

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

    module: {
        rules: [
]},
plugins: [
        new webpack.ContextReplacementPlugin(
            // The (\\|\/) piece accounts for path separators in *nix and Windows
            /angular(\\|\/)core(\\|\/)(esm(\\|\/)src|src)(\\|\/)linker/,
            helpers.root('./src'), // location of your src
            {} // a map of your routes
        ),

        new webpack.optimize.CommonsChunkPlugin({
            name: ['app', 'vendor', 'polyfills']
        }),

【讨论】:

  • 对于 Typescript 2,我们可以使用类型化,也可以包含在开发者依赖项下,例如 '@types/node'、'@types/jasmine'、'@types/core-js'
  • 我希望不要用我的 webfig.js 污染论坛,但看来我必须这样做。请看编辑。它几乎和你的一样。而且我不清楚错误的根源在哪里。
猜你喜欢
  • 2018-11-11
  • 2021-05-29
  • 2019-04-25
  • 1970-01-01
  • 2023-03-21
  • 2019-09-04
  • 1970-01-01
  • 2022-09-30
  • 2016-11-07
相关资源
最近更新 更多