SCRIPT1003:预期':'

时间:2018-05-14 13:42:13

标签: javascript typescript internet-explorer webpack

我知道这个标题有很多问题

但我有这个

  

SCRIPT1003:预期':'(1,78)

启动网站时

我在我的项目中使用webpack和typescript

这是tsconfig

   {
  "compilerOptions": {
    "declaration": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "typeRoots": [
      "./node_modules/@types"
    ],
    "types": [ "jquery", "accounting","js-cookie" ],
    "lib": ["es6", "dom"],
    "allowSyntheticDefaultImports": true,
    "module": "es6",
    "moduleResolution": "node",
    "sourceMap": true,
    "target": "es5"
  },
  "exclude": [
    "**/*.spec.ts",
    "node_modules",
    "vendor",
    "public"
  ],
  "compileOnSave": false
}

这是webpack的enviroment.js

 const { environment } = require("@rails/webpacker");
const { resolve } = require("path");
const webpack = require("webpack");
const typescript =  require("./loaders/typescript");
const HoneybadgerSourceMapPlugin = require("@honeybadger-io/webpack");
const revision = process.env.GIT_COMMIT || "master";
const apiKey =  "***********";
const assetsUrl =  "*/packs";

environment.plugins.prepend("Provide",  new webpack.ProvidePlugin({
    $: "jquery",
    jQuery: "jquery",
    jquery: "jquery",
    "window.Tether": "tether",
  })
);

if (process.env.NODE_ENV === "production") {
  environment.plugins.prepend(
    "HoneybadgerSourceMap",
    new HoneybadgerSourceMapPlugin({
      apiKey: apiKey,
      assetsUrl: assetsUrl,
      silent: false,
      ignoreErrors: false,
      revision: revision
    })
  );
}

const config = environment.toWebpackConfig();
config.resolve.alias = {
  jquery: "jquery/src/jquery",
};

config.externals = {
  gon: "gon"
};

environment.loaders.get("sass").use.find((item) => item.loader === "sass-loader").options.includePaths = [resolve("app", "javascript", "themes")];
environment.loaders.append("typescript", typescript);

module.exports = environment;
  

行(1,78)代码

  var o = e[i] ={
i,
l: !1,
exports :{}
};

但我认为这似乎是webpack的自动生成代码。

哪里可能有问题以及如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

我猜是几年太晚了,但我也遇到了这个错误。

解决方案是添加

if (environment.plugins.getIndex('UglifyJs') !== -1) {
  const plugin = environment.plugins.get('UglifyJs');
  plugin.options.uglifyOptions.ecma = 5;
}

到你的environment.js

希望它可以帮助某人

在这里我找到了解决方案: https://github.com/rails/webpacker/issues/1235