Skip to content

Svelte got ERROR when @babel/preset-env target was 'ie >= 11' #4528

Closed
@rhinonan

Description

@rhinonan

Describe the bug

Using webpack4 & babel7 to dev svelte application. Now it's just a 'hello world'. I need make it work on IE 11。

I use bable & babel-preset-env to translate js code. It's work fine when browsers was chrome,but when i change it to ie >= 11,it got an Error.

Logs

log.js:59 Uncaught TypeError: Class constructor SvelteComponent cannot be invoked without 'new'
    at new Componets (log.js:59)
    at Module../src/index.js (index.js:6)
    at __webpack_require__ (bootstrap:725)
    at fn (bootstrap:100)
    at Object.0 (app.js:15268)
    at __webpack_require__ (bootstrap:725)
    at bootstrap:792
    at bootstrap:792

To Reproduce

<!-- componet.svelte -->
<div class="svelte">
    <div>这是一个svelte组件(红框)</div>
</div>

here is my webpack.config.js

const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const webpack = require('webpack');

module.exports = {
  entry: {
    app: "./src/index.js"
  },
  devtool: "inline-source-map",
  plugins: [
    new CleanWebpackPlugin(),
    new HtmlWebpackPlugin({
      title: "Output Management",
      template: "./index.html"
    }),
    new webpack.NamedModulesPlugin(),
    new webpack.HotModuleReplacementPlugin()
  ],
  module: {
    rules: [
      {
        test: /(\.m?js?$)|(\.svelte$)/,
        exclude: /(node_modules|bower_components)/,
        use: {
          loader: "babel-loader",
          options: {
            presets: [
              [
                "@babel/preset-env",
                {
                  targets: {
                    browsers: ["ie >= 11"]
                  },
                  useBuiltIns: "usage",
                  corejs: 3
                }
              ]
            ]
          }
        }
      },
      {
        test: /\.(svelte)$/, // 不能使用html后缀
        exclude: /node_modules/,
        use: "svelte-loader"
      },
      {
        test: /\.css$/,
        use: ["style-loader", "css-loader"]
      }
    ]
  },
  devServer: {
    contentBase: "./dist",
    hot: true,
    host: "0.0.0.0",
    open: false,
    overlay: true
  },
  output: {
    filename: "[name].js",
    path: path.resolve(__dirname, "dist")
  }
};

Who can help me?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions