Skip to content
This repository has been archived by the owner on Oct 1, 2020. It is now read-only.

SyntaxError: Unexpected token import #287

Open
Gum-Joe opened this issue Jan 11, 2018 · 0 comments
Open

SyntaxError: Unexpected token import #287

Gum-Joe opened this issue Jan 11, 2018 · 0 comments

Comments

@Gum-Joe
Copy link

Gum-Joe commented Jan 11, 2018

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:

  • Ran npm install
  • Updated all the babel packages to use the @babel scope
  • Tried packaging the application (I am using electron-forge), which seems to be failing to compile the JS with the error Cannot read property 'method' of undefined (although this might be an entirely separate issue).

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!

@Gum-Joe Gum-Joe changed the title SyntaxError: Unexpected token import (likely config error) SyntaxError: Unexpected token import Jan 11, 2018
Gum-Joe added a commit to Gum-Joe/tara that referenced this issue May 6, 2018
After electron-compile stopped working (electron-userland/electron-compile#287), we decided to move to using electron-webpack. After some issues (electron-userland/electron-webpack#83), we managed to get the app running.

Major changes:
- address-bar is now part of explorer
- Core logic is now in `tara-core`
- Explorer is now less buggy
- Now using electron-webpack instead of electron-compile.

Related Issues & PRs:
#12 
#13 
#14 
#15 

Special thanks to @loopmode for advice & help!
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant