electron-userland / electron-compile

DEPRECATED: Electron supporting package to compile JS and CSS in Electron applications
1.01k stars 99 forks source link

SyntaxError: Unexpected token import #287

Open Gum-Joe opened 6 years ago

Gum-Joe commented 6 years ago

Hi all, I've recently run into an issue where I can't seem to get my code running. The error (with debug output) is as follows:

Thu, 11 Jan 2018 21:57:04 GMT electron-compile:sanitize-paths Cache miss for cachedRealpath: 'D:\Users\Kishan\Documents\Projects\tara' => 'D:\Users\Kishan\Documents\Projects\tara'
App threw an error during load
D:\Users\Kishan\Documents\Projects\tara\src\renderer\index.js:7
import "@babel/polyfill"; // ES6 Polyfill
^^^^^^

SyntaxError: Unexpected token import
  at createScript (vm.js:74:10)
  at Object.runInThisContext (vm.js:116:10)
  at Module._compile (module.js:533:28)
  at Object.Module._extensions..js (module.js:580:10)
  at Module.load (module.js:503:32)
  at tryModuleLoad (module.js:466:12)
  at Function.Module._load (module.js:458:3)
  at Module.require (module.js:513:17)
  at init (D:\Users\Kishan\Documents\Projects\tara\node_modules\electron-compile\lib\config-parser.js:294:16)
  at main (D:\Users\Kishan\Documents\Projects\tara\node_modules\electron-prebuilt-compile\lib\es6-init.js:56:29)

I hypothesise (and please note that I am no expert) that the compiler is not transpiling the code correctly. Upon further investigation, when running the precompile command, that the compilers weren't found when they were called to be loaded (although this might not be related).

I have already:

My .compilerc is as follows:

{
  "env": {
    "development": {
      "application/javascript": {
        "presets": [
          [
            "@babel/preset-env",
            {
              "targets": {
                "electron": "1.8.1"
              }
            }
          ],
          "@babel/preset-react"
        ],
        "plugins": [
          "@babel/plugin-transform-async-to-generator",
          "react-hot-loader/babel",
          "babel-plugin-transform-object-rest-spread",
          "babel-plugin-transform-export-extensions"
        ],
        "sourceMaps": "inline"
      },
      "text/typescript": {
        "module": "CommonJS",
        "noImplicitAny": true,
        "removeComments": false,
        "preserveConstEnums": true,
        "sourceMap": true
      }
    },
    "production": {
      "application/javascript": {
        "presets": [
          [
            "@babel/preset-env",
            {
              "targets": {
                "electron": "1.8.1"
              }
            }
          ],
          "@babel/preset-react"
        ],
        "plugins": [
          "@babel/plugin-transform-async-to-generator",
          "babel-plugin-transform-object-rest-spread",
          "babel-plugin-transform-export-extensions"
        ],
        "sourceMaps": "none"
      },
      "text/typescript": {
        "module": "CommonJS",
        "noImplicitAny": true,
        "removeComments": true,
        "preserveConstEnums": true,
        "sourceMap": false
      }
    }
  }
}

Any help will be appreciated. Please ask if you require any more information.

Thanks in advanced!