Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot import ES6 modules on windows #93

Closed
deepak opened this issue Jan 20, 2017 · 11 comments
Closed

Cannot import ES6 modules on windows #93

deepak opened this issue Jan 20, 2017 · 11 comments

Comments

@deepak
Copy link

deepak commented Jan 20, 2017

The same code was running on Windows and OSX.
But it randomly stopped working on Windows 10

error is:

import { app, BrowserWindow } from 'electron';
^^^ 
SyntaxError: Unexpected token import

screenshot of the error is:

electron-forge-cannot-import

I do not have a testcase as such. it randomly stopped working
but the sample app is at https://github.com/deepak/electron-webview-todo/

i am using Powershell ISC on Windows 10 for running npm start

Console output when you run electron-forge with the environment variable DEBUG=electron-forge:*.

PS C:\Users\Deepak\Documents\Visual Studio 2013\Projects\electron-webview-todo> npm start

> electron-webview-todo@0.0.1 start C:\Users\Deepak\Documents\Visual Studio 2013\Projects\electron-webview-todo
> cross-env DEBUG=electron-forge:* electron-forge start --enable-logging

npm : WARNING: DEBUG environment variable detected.  Progress indicators will be sent over electron-forge:lifecycle
At line:1 char:1
+ npm start
+ ~~~~~~~~~
    + CategoryInfo          : NotSpecified: (WARNING: DEBUG ...forge:lifecycle:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError
 
Fri, 20 Jan 2017 10:39:29 GMT electron-forge:lifecycle Process Started: Checking your system
Fri, 20 Jan 2017 10:39:29 GMT electron-forge:lifecycle Process Succeeded: Checking your system
Fri, 20 Jan 2017 10:39:29 GMT electron-forge:runtime-config setting key: verbose to value: false
WARNING: DEBUG environment variable detected.  Progress indicators will be sent over electron-forge:lifecycle
Fri, 20 Jan 2017 10:39:31 GMT electron-forge:lifecycle Process Started: Locating Application
Fri, 20 Jan 2017 10:39:31 GMT electron-forge:project-resolver searching for project in: 
C:\Users\Deepak\Documents\Visual Studio 2013\Projects\electron-webview-todo
Fri, 20 Jan 2017 10:39:31 GMT electron-forge:project-resolver electron-forge compatible package.json found in 
C:\Users\Deepak\Documents\Visual Studio 2013\Projects\electron-webview-todo\package.json
Fri, 20 Jan 2017 10:39:31 GMT electron-forge:lifecycle Process Succeeded: Locating Application
Fri, 20 Jan 2017 10:39:31 GMT electron-forge:lifecycle Process Started: Preparing native dependencies
Fri, 20 Jan 2017 10:39:31 GMT electron-forge:lifecycle Process Succeeded: Preparing native dependencies
Fri, 20 Jan 2017 10:39:31 GMT electron-forge:lifecycle Process Started: Launching Application
Fri, 20 Jan 2017 10:39:31 GMT electron-forge:lifecycle Process Succeeded: Launching Application

App threw an error during load
C:\Users\Deepak\Documents\Visual Studio 2013\Projects\electron-webview-todo\src\main-process\main.js:5
import { app, BrowserWindow } from 'electron';
^^^^^^
SyntaxError: Unexpected token import
    at Object.exports.runInThisContext (vm.js:76:16)
    at Module._compile (module.js:528:28)
    at Object.Module._extensions..js (module.js:565:10)
    at Module.load (module.js:473:32)
    at tryModuleLoad (module.js:432:12)
    at Function.Module._load (module.js:424:3)
    at loadApplicationPackage (C:\Users\Deepak\Documents\Visual Studio 2013\Projects\electron-webview-todo\node_module
s\electron\dist\resources\default_app.asar\main.js:280:12)
    at Object.<anonymous> (C:\Users\Deepak\Documents\Visual Studio 2013\Projects\electron-webview-todo\node_modules\el
ectron\dist\resources\default_app.asar\main.js:322:5)
    at Module._compile (module.js:556:32)
    at Object.Module._extensions..js (module.js:565:10)

What command line arguments are you passing?

command to start Elecron is:

cross-env DEBUG=* electron-forge start --enable-logging

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

{
    "forge": {
      "make_targets": {
        "win32": [
          "squirrel"
        ],
        "darwin": [
          "zip"
        ],
        "linux": [
          "deb",
          "rpm"
        ]
      },
      "electronPackagerConfig": {},
      "electronWinstallerConfig": {
        "name": "electron-webview-todo"
      },
      "electronInstallerDebian": {},
      "electronInstallerRedhat": {},
      "github_repository": {
        "owner": "",
        "name": ""
      }
    }
  }
@MarshallOfSound
Copy link
Member

But it randomly stopped working on Windows 10

Nothing happens randomly, you probably deleted the .compilerc by accident or corrupted your node_modules directory or something similar. On a fresh clone your repository I do not encounter this error so I can only assume that something has broken in your local.

Perhaps one of the issues mentioned above, perhaps not. You should try resetting your local dev environment.

@deepak
Copy link
Author

deepak commented Jan 20, 2017

Nothing happens randomly, you probably deleted the .compilerc by accident

I do not know even where the .compilerc file is. so am assuming did not delete it
where is the .compilerc file on windows and OSX ?

By random, i meant that it was working before and then stopped working
Can i request a electro-forge doctor command to check the dependencies

I tried after reinstalling electron-forge as well with "npm install -g electron-forge"

@MarshallOfSound
Copy link
Member

If electron-forge start get's passed the "Locating application" phase we believe the required config is there. This does not mean that you have everything installed correctly however.

Try completely recloning your repository, who knows what could have been deleted / edited / broken.

@deepak
Copy link
Author

deepak commented Jan 20, 2017

thanks @MarshallOfSound. will try it out

@deepak
Copy link
Author

deepak commented Jan 20, 2017

If electron-forge start get's passed the "Locating application"
phase we believe the required config is there

in my case the application is starting up but the above error is thrown
and this happens only on windows. application starts and works on OSX

there was a separate error on OSX
due to hard disk getting full. but there was no such issue on windows. ie. hard disk was not full etc
so not sure why this error is occurring

so i suggested a "homebrew doctor" command
so check all the dependencies

even a list of manual steps to check the system would be nice to have
re-installing the whole system (in case it stops working) does seems painful

@MarshallOfSound
Copy link
Member

@deepak I'm not sure what to tell you, I cloned your repository onto a Windows 10 machine and ran yarn followed by electron-forge start. It worked perfectly.

Whatever error you are getting appears to be due to the compiler not kicking in which normally occurs due to a misconfigured .compilerc.

As such the best I can suggest (as I said before) is effectively recloning your repository and starting the same way I did. If the error still occurs on a clean clone of your repository on your machine I can potentially look into more debugging

@deepak
Copy link
Author

deepak commented Jan 20, 2017

@MarshallOfSound it worked after

  1. reinstalling node
  2. installing electron-forge in global
  3. npm installing dependencies

@krimark
Copy link

krimark commented Jun 25, 2017

Same error here but the steps described by deepak above does not help in my case.

@malept
Copy link
Member

malept commented Jun 25, 2017

@krimark do you have a minimal, sample app that we can use to reproduce?

@krimark
Copy link

krimark commented Jun 26, 2017

Hi, what I do is to simply initialize a new projekt using the angular 2 template from here: https://beta.electronforge.io/templates and I also add electron to the dev dependencies with npm install electron --save-dev because otherwise I get red squiggles in VS Code on the line import { app, BrowserWindow } from 'electron'; If I just run the code without first installing electron it seems to work but I don't understand why as electron is not present in node_modules at that time.

electron_test

@malept
Copy link
Member

malept commented Jun 26, 2017

Yeah, don't install electron directly onto the project. electron is a dependency of electron-prebuilt-compile (which is installed by default), but it does not install electron into the top-level node_modules (because of installation conflicts). What you're seeing with the red squiggle sounds like a VSCode bug.

dsanders11 pushed a commit that referenced this issue Jan 14, 2023
fix: Prevent error in isContentUnchanged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants