question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Getting: Unexpected token import

See original GitHub issue
  • I have read the contribution documentation for this project.
  • I agree to follow the code of conduct that this project follows, as appropriate.
  • I have searched the issue tracker for an issue that matches the one I want to file, without success.

Please describe your issue: In “dev mode” all works right, but once I run a packaged application it throws me that error:

Uncaught Exception:
/Users/rawnly/Code/ELECTRON/APPS/snahp-tool/out/snahp-tool-darwin-x64/snahp-tool.app/Contents/Resources/app/src/app.js:1
(function (exports, require, module, __filename, __dirname, process, global, Buffer) { return function (exports, require, module, __filename, __dirname) { import { app, BrowserWindow, Menu } from 'electron';
                                                                                                                                                           ^^^^^^

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.require.extensions.(anonymous function) [as .js] (/Users/rawnly/Code/ELECTRON/APPS/snahp-tool/out/snahp-tool-darwin-x64/snahp-tool.app/Contents/Resources/app/node_modules/electron-compile/lib/require-hook.js:77:14)
    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 Object.init (/Users/rawnly/Code/ELECTRON/APPS/snahp-tool/out/snahp-tool-darwin-x64/snahp-tool.app/Contents/Resources/app/node_modules/electron-compile/lib/config-parser.js:294:16)
    at Object.<anonymous> (/Users/rawnly/Code/ELECTRON/APPS/snahp-tool/out/snahp-tool-darwin-x64/snahp-tool.app/Contents/Resources/app/es6-shim.js:8:17)

Console output when you run electron-forge with the environment variable DEBUG=electron-forge:*. (Instructions on how to do so here). Please include the stack trace if one exists.

 None

What command line arguments are you passing?

 None

What does your config.forge data in package.json look like?

"config": {
    "forge": {
      "make_targets": {
        "win32": [
          "squirrel"
        ],
        "darwin": [
          "zip"
        ],
        "linux": [
          "deb",
          "rpm"
        ]
      },
      "electronPackagerConfig": {
        "packageManager": "yarn"
      },
      "electronWinstallerConfig": {
        "name": "snahp_tool"
      },
      "electronInstallerDebian": {},
      "electronInstallerRedhat": {},
      "github_repository": {
        "owner": "Rawnly",
        "name": "rawnly/snahp-downloader"
      },
      "windowsStoreConfig": {
        "packageName": "",
        "name": "snahptool"
      }
    }
  }

Please provide either a failing minimal testcase (with a link to the code) or detailed steps to reproduce your problem. Using electron-forge init is a good starting point, if that is not the source of your problem.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:5
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
idancalicommented, Mar 28, 2018

@malept It’s easy to reproduce this - I have this issue as well.

The trouble is that you cannot import any ES6 module from node_modules. So if you simply add a folder name _test to your node_modules with an index.js file containing a one-liner like say import React from 'react' this will not work.

It looks like electron-forge ignores node_modules completely.

Is there any way to modify that somewhere so that it ignores everything except a few selected modules?

0reactions
MarshallOfSoundcommented, Apr 16, 2018

Duplicate #212

Read more comments on GitHub >

github_iconTop Results From Across the Web

Node.js - SyntaxError: Unexpected token import - Stack Overflow
My project is working great with imports now, but when I use the code in the question, I first get an error for...
Read more >
SyntaxError: Unexpected token import in Node.js | bobbyhadz
The "SyntaxError: Unexpected token import" occurs when we use the ES6 import syntax in a version of Node that doesn't support it. To...
Read more >
Unexpected token import Node.js - Reactgo
In this tutorial, we are going to learn about how to resolve the unexpected token import error in Node.js.
Read more >
JavaScript ES6 - How to fix Unexpected token import - YouTube
This video is a short explanation on how to fix the syntax error: " Unexpected Token Import "Hint: type="module"
Read more >
ES6 modules in the browser - Unexpected token import
I read ES6 is supported by Firefox and Chrome, but I'm getting the following error using export. Uncaught SyntaxError: Unexpected token import.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found