electron-userland / electron-forge-templates

Templates bundled with Electron Forge <= 5 to create Electron apps using popular JavaScript frameworks
107 stars 23 forks source link

Angular2 SyntaxError: Unexpected token import #45

Closed casc99 closed 7 years ago

casc99 commented 7 years ago

Please describe your issue: On a fresh angular2 project after npm install I get this error:

SyntaxError: Unexpected token import
    at Object.exports.runInThisContext (vm.js:78:16)
    at Module._compile (module.js:543:28)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at loadApplicationPackage (/home/newProj/node_modules/electron/dist/resources/default_app.asar/main.js:283:12)
    at Object.<anonymous> (/home/newProj/node_modules/electron/dist/resources/default_app.asar/main.js:325:5)
    at Object.<anonymous> (/home/newProj/node_modules/electron/dist/resources/default_app.asar/main.js:361:3)
    at Module._compile (module.js:571:32)

Environment:

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

$ DEBUG=electron-forge:* electron-forge start
WARNING: DEBUG environment variable detected.  Progress indicators will be sent over electron-forge:lifecycle
  electron-forge:lifecycle Process Started: Checking your system +0ms
  electron-forge:lifecycle Process Succeeded: Checking your system +10ms
  electron-forge:runtime-config setting key: verbose to value: false +4ms
WARNING: DEBUG environment variable detected.  Progress indicators will be sent over electron-forge:lifecycle
  electron-forge:lifecycle Process Started: Locating Application +0ms
  electron-forge:project-resolver searching for project in: /home/newProj +2ms
  electron-forge:project-resolver electron-forge compatible package.json found in /home/newProj/package.json +3ms
  electron-forge:lifecycle Process Succeeded: Locating Application +1ms
  electron-forge:lifecycle Process Started: Preparing native dependencies +0ms
  electron-forge:lifecycle Process Succeeded: Preparing native dependencies +35ms
  electron-forge:hook could not find hook: generateAssets +4ms
  electron-forge:lifecycle Process Started: Launching Application +0ms
  electron-forge:lifecycle Process Succeeded: Launching Application +3ms
App threw an error during load
/home/newProj/src/index.ts:1
(function (exports, require, module, __filename, __dirname, process, global, Buffer) { return function (exports, require, module, __filename, __dirname) { import { app, BrowserWindow } from 'electron';
                                                                                                                                                           ^^^^^^
SyntaxError: Unexpected token import
    at Object.exports.runInThisContext (vm.js:78:16)
    at Module._compile (module.js:543:28)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at loadApplicationPackage (/home/newProj/node_modules/electron/dist/resources/default_app.asar/main.js:283:12)
    at Object.<anonymous> (/home/newProj/node_modules/electron/dist/resources/default_app.asar/main.js:325:5)
    at Object.<anonymous> (/home/newProj/node_modules/electron/dist/resources/default_app.asar/main.js:361:3)
    at Module._compile (module.js:571:32)
A JavaScript error occurred in the main process
Uncaught Exception:
/home/newProj/src/index.ts:1
(function (exports, require, module, __filename, __dirname, process, global, Buffer) { return function (exports, require, module, __filename, __dirname) { import { app, BrowserWindow } from 'electron';
                                                                                                                                                           ^^^^^^
SyntaxError: Unexpected token import
    at Object.exports.runInThisContext (vm.js:78:16)
    at Module._compile (module.js:543:28)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at loadApplicationPackage (/home/newProj/node_modules/electron/dist/resources/default_app.asar/main.js:283:12)
    at Object.<anonymous> (/home/newProj/node_modules/electron/dist/resources/default_app.asar/main.js:325:5)
    at Object.<anonymous> (/home/newProj/node_modules/electron/dist/resources/default_app.asar/main.js:361:3)
    at Module._compile (module.js:571:32)

Please provide either a failing minimal testcase (with a link to the code) or detailed steps to reproduce your problem.

electron-forge init newProj --template=angular2
cd newProj
electron-forge start (ok)
npm install
electron-forge start (error)

npm install output:

$ npm install
npm WARN deprecated @types/electron@1.6.10: This is a stub types definition for electron (https://github.com/electron/electron). electron provides its own type definitions, so you don't need @types/electron installed!
npm WARN deprecated jade@1.11.0: Jade has been renamed to pug, please install the latest version of pug instead of jade
npm WARN deprecated transformers@2.1.0: Deprecated, use jstransformer
npm WARN gentlyRm not removing /home/newProj/node_modules/tslint/node_modules/.bin/tsc as it wasn't installed by /home/newProj/node_modules/tslint/node_modules/typescript
npm WARN gentlyRm not removing /home/newProj/node_modules/tslint/node_modules/.bin/tsserver as it wasn't installed by /home/newProj/node_modules/tslint/node_modules/typescript
npm WARN gentlyRm not removing /home/newProj/node_modules/electron-compilers/node_modules/.bin/tsc as it wasn't installed by /home/newProj/node_modules/electron-compilers/node_modules/typescript
npm WARN gentlyRm not removing /home/newProj/node_modules/electron-compilers/node_modules/.bin/tsserver as it wasn't installed by /home/newProj/node_modules/electron-compilers/node_modules/typescript
npm WARN gentlyRm not removing /home/newProj/node_modules/.bin/uglifyjs as it wasn't installed by /home/newProj/node_modules/uglify-js
npm WARN gentlyRm not removing /home/newProj/node_modules/.bin/mkdirp as it wasn't installed by /home/newProj/node_modules/mkdirp
npm WARN gentlyRm not removing /home/newProj/node_modules/.bin/browserslist as it wasn't installed by /home/newProj/node_modules/browserslist

> electron@1.6.11 postinstall /home/newProj/node_modules/electron
> node install.js

npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN newProj@1.0.0 No repository field.

added 36 packages, removed 26 packages and updated 579 packages in 20.022s
MarshallOfSound commented 7 years ago

Can you delete your node_modules and run npm i again. Sounds like a module install issue

casc99 commented 7 years ago
$ rm -rf ./node_modules/
$ npm cache clean --force
$ npm i
$ electron-forge start (same error)
casc99 commented 7 years ago

No errors with node@7.5.0 and npm@4.1.2 . So seems related to node 8 .

MarshallOfSound commented 7 years ago

@casc99 Probably an npm@5 thing rather than a node issues

MarshallOfSound commented 7 years ago

See https://github.com/electron-userland/electron-forge/issues/269