SCRIPT1014:IE11 / webpack / Babel / Foundation上的Caractère错误

时间:2019-03-22 11:57:10

标签: jquery webpack zurb-foundation babel babel-loader

我正在更新对我网站的依赖。 在最近的浏览器,Edge,Chrome,Firefox上运行良好。

但是在IE11上,我得到“ SCRIPT1014:Caractère错误” 在此行上:

eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"Foundation\", function

我认为babel配置良好,可以在IE11上运行,但事实并非如此。

这是我的配置文件 Package.json:

{
  "name": "project_name",
  "version": "3.0.0",
  "description": "Starter project by us, build with foundation 6 & compiled with webpack 4",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "dev": "webpack --mode development --watch",
    "build": "cross-env NODE_ENV=production webpack --progress",
    "proxy": "./node_modules/.bin/browser-sync start --config ./proxy.dev.json"
  },
  "keywords": [],
  "author": "Me",
  "license": "ISC",
  "devDependencies": {
    "autoprefixer": "^8.6.0",
    "babel-cli": "^6.26.0",
    "babel-core": "^6.26.3",
    "babel-loader": "^7.1.4",
    "babel-preset-env": "^1.7.0",
    "browser-sync": "^2.26.3",
    "cross-env": "^5.1.6",
    "css-loader": "^0.28.11",
    "mini-css-extract-plugin": "^0.5.0",
    "node-sass": "^4.11.0",
    "optimize-css-assets-webpack-plugin": "^4.0.2",
    "postcss-loader": "^2.1.5",
    "sass-loader": "^6.0.7",
    "style-loader": "^0.23.1",
    "webpack": "^4.20.2",
    "webpack-cli": "^3.0.2"
  },
  "dependencies": {
    "jquery": "^3.2.1",
    "foundation-sites": "^6.5.1",
    "slick-carousel": "^1.6.0",
    "cleave.js": "^0.7.15",
    "family.scss": "^1.0.8",
    "url-safe-string": "^1.1.0",
    "jquery.easing": "1.4.1",
    "jquery-colorbox": "^1.6.4",
    "select2": "^4.0.3"
  }
}

.babelrc

    {
  "presets" : [
    ["env", {
      "targets": {
        "browsers": ["last 2 versions", "ie >= 11"]
      }
    }],
  ]
}

webpack.config.js

    // webpack v4

const webpack = require('webpack');
const path = require('path');

// pour créer le fichier CSS on utilise extractText
const MiniCssExtractPlugin = require("mini-css-extract-plugin");

// pour minifier le CSS
const OptimizeCSSAssets = require("optimize-css-assets-webpack-plugin");
new OptimizeCSSAssets();

const devMode = process.env.NODE_ENV !== 'production';
var nodePath = path.resolve(__dirname, 'node_modules');

module.exports = {
    entry: [ './src/index.js'],
    output: {
        path: path.resolve(__dirname, '../public/assets'),
        filename: 'bundleV4.js'
    },
    module: {
        rules: [
            // babel converts ES6 JS into old-browser friendly JS, see .babelrc for more details
            {
                test: /\.js$/,
                exclude: /(node_modules|bower_components)/,
                use: {
                    loader: "babel-loader"
                }
            },
            // allow SCSS to be compiled in CSS
            {
                test: /\.(sa|sc|c)ss$/,
                use: [
                    devMode ? 'style-loader' : MiniCssExtractPlugin.loader,
                    'css-loader',
                    'postcss-loader',
                    'sass-loader',
                ],
            }

        ]
    },
    plugins: [
        new MiniCssExtractPlugin({
            // Options similar to the same options in webpackOptions.output
            // both options are optional
            filename: "appV4.css",
            chunkFilename: "[id].css"
        }),
        new webpack.ProvidePlugin({
            $: 'jquery',
            jQuery: 'jquery',
            'window.jQuery': 'jquery'
        })
    ],
};

// minify CSS for production
if (process.env.NODE_ENV === 'production') {
    module.exports.plugins.push(new OptimizeCSSAssets());
}

2 个答案:

答案 0 :(得分:1)

谢谢你丹尼尔·鲁夫,我找到了解决方案。

我删除了.babelrc

并将其放在我的webpack.config.js文件中:

 module: {
    rules: [
        // babel converts ES6 JS into old-browser friendly JS, see .babelrc for more details
        {
            test: /\.js$/,

            use: {
                loader: "babel-loader",
                options: {
                    presets: ['@babel/preset-env'],
                    plugins: ['@babel/plugin-proposal-object-rest-spread']
                }

            }
        },

答案 1 :(得分:0)

可能是缺少一些转换插件。 尝试使用babel-plugin-transform-es2015-template-literals添加npm i babel-plugin-transform-es2015-template-literals -D并将其添加到您的.babelrc

{
  "presets" : [
    ["env", {
      "targets": {
        "browsers": ["last 2 versions", "ie >= 11"]
      }
    }],
  ],
  "plugins": ["transform-es2015-template-literals"]
}

请参见https://babeljs.io/docs/en/babel-plugin-transform-template-literals