electron-userland / electron-compile

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

importing webpack causes fatal exception #210

Closed aeneasr closed 7 years ago

aeneasr commented 7 years ago

I used electron-compile a while ago but since electron-builder didn't support it, I had a toolchain that first transpiled JSX using babel and then ran electron from the directory where the transpiled files where at. Now that electron-builder finally supports electron-compile, I wanted to switch back. Unfortunately, using electron-prebuilt-compile, I was unable to start the project as I received this error:

App threw an error during load
C:\workspace\js\sites-app\node_modules\webpack\lib\WebpackOptionsApply.js:209
                        comment = legacy && modern ? "\n/*\n//@ sourceMappingURL=[url]\n//# sourceMappingURL=node_modules\webpack\lib\[url]\n*\" :
                                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: Invalid or unexpected token
    at Object.exports.runInThisContext (vm.js:78:16)
    at Module._compile (module.js:543:28)
    at Object.require.extensions.(anonymous function) [as .js] (C:\workspace\js\sites-app\node_modules\electron-compile\lib\require-hook.js:75:14)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.require (module.js:498:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (C:\workspace\js\sites-app\node_modules\webpack\lib\webpack.js:10:29)
    at Object.<anonymous> (C:\workspace\js\sites-app\node_modules\webpack\lib\webpack.js:121:3)
    at Module._compile (module.js:571:32)
    at Object.require.extensions.(anonymous function) [as .js] (C:\workspace\js\sites-app\node_modules\electron-compile\lib\require-hook.js:75:14)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.require (module.js:498:17)

I'm actually importing webpack in my app

import React from 'react'
import webpack from 'webpack'

primarily because I want to build third party code using the electron-app and webpack. When I remove the webpack dependency, the app compiles.

aeneasr commented 7 years ago

When I inspect the code, I see that there is a small difference. Above, the line escapes the last quote:

comment = legacy && modern ? "\n/*\n//@ sourceMappingURL=[url]\n//# sourceMappingURL=node_modules\webpack\lib\[url]\n*\" :

while in the code, the last quote is not escaped:

comment = legacy && modern ? "\n/*\n//@ sourceMappingURL=[url]\n//# sourceMappingURL=[url]\n*/"

Additionally, it seems like the string node_modules\webpack\lib was injected?

aeneasr commented 7 years ago

Is there really no one who can help me with this?

aeneasr commented 7 years ago

When setting DEBUG=* these are the logs:

$ npm run start:electron | grep WebpackOptionsApply
Fri, 14 Apr 2017 16:20:12 GMT electron-compile:compiler-host Compiling C:\workspace\js\sites-app\app\node_modules\webpack\lib\WebpackOptionsApply.js
Fri, 14 Apr 2017 16:20:12 GMT electron-compile:sanitize-paths Cache miss for cachedRealpath: 'C:\workspace\js\sites-app\app\node_modules\webpack\lib\WebpackOptionsApply.js' => 'C:\workspace\js\sites-app\app\node_modules\webpack\lib\WebpackOptionsApply.js'
Fri, 14 Apr 2017 16:20:12 GMT electron-compile:file-change-cache Cache entry for /node_modules/webpack/lib/WebpackOptionsApply.js: {"ctime":1491859282178,"size":11342,"info":{"hash":"2285a98358d4b0997095fe757b2cfa80ef920276","isMinified":false,"isInNodeModules":tr
ue,"hasSourceMap":false,"isFileBinary":false}}
C:\workspace\js\sites-app\app\node_modules\webpack\lib\WebpackOptionsApply.js:209 # this is the error
aeneasr commented 7 years ago

I believe this to be an issue with electron-compilers. I'll reopen here if it isn't.