Tìm kiếm trang web

node.js - Các kiểu TypeScript bị hỏng (lỗi TS2687): Tất cả các khai báo của 'iterator' phải có các bộ chỉnh sửa giống nhau


Tôi đang gặp vấn đề trong việc nhận các kiểu dữ liệu đúng sau khi tôi thêm gói router vào ứng dụng Angular của mình (điều này yêu cầu nâng cấp Core, Common, Compiler, v.v.).

Tìm kiếm trên Google về mã lỗi cụ thể đó đã dẫn tôi đến một số vấn đề, giải pháp chính cho những vấn đề này là xóa node_modules và typings và tạo lại chúng. Tôi đã làm như vậy nhưng vẫn gặp phải hành vi sai tương tự.

Trên SO, có một câu hỏi khác nhưng nó cũ, liên quan đến các phiên bản khác của hầu hết các gói và tôi hầu như không thấy nó liên quan đến vấn đề của tôi.

Thành thật mà nói, tôi hơi bối rối vì tôi hoàn toàn không biết cách khắc phục sự cố này. Dưới đây là tsconfig.json của tôi nếu nó giúp phát hiện điều gì đó bất thường.

chỉnh sửa

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" }])
  ]
}

Câu trả lời #1

Trong Webpack.common.js, hãy xóa dòng debug=true và thay đổi đoạn mã dưới đây

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']
        }),