Closed aeneasr closed 7 years ago
Please don't raise duplicates cross-repositories. If someone determines the first issue you raised belongs here then the first one should be closed and this should remain. Please choose one to close
I wasn't sure if the maintainers are the same :) Sorry for the dupe, I should have referenced an upstream link. I think the issue is caused by electron-compilers as there has to be some transpiling going on for this to happen.
Would a reproducible case help here? I really have no idea where to start looking, it seems like electron-compile is doing some fancy directory walking.
A repro case always helps :)
This sounds like a Babel issue though. Try running that webpack file through Babel by itself and see if the output is legit or not
I did that, the output is legit. However I don't know if maybe this is caused by some sourcemap logic which isnt possible on babeljs.io?
I create a reproducible case here: https://github.com/arekkas/electron-compile-webpack-bug
This is the line causing the bug.
I'm not so sure if this is really caused by babel/webpack (at least I was not able to reproduce it yet) itself, but rather by this loc. For some reason it looks like that line is being invoked from at Object.<anonymous> (C:\workspace\js\electron-compile-webpack-bug\node_modules\webpack\lib\webpack.js:10:29)
(const WebpackOptionsApply = require("./WebpackOptionsApply");
).
I also tried transpiling
let legacy, modern
const comment = legacy && modern ? "\n/*\n//@ sourceMappingURL=[url]\n//# sourceMappingURL=[url]\n*/" :
legacy ? "\n/*\n//@ sourceMappingURL=[url]\n*/" :
modern ? "\n//# sourceMappingURL=[url]" :
null;
console.log(comment)
with various babel set ups in the index.js of my app, but it always worked. I then created a new npm package which I called foo and which had only one main.js
file with these contents:
const comment = legacy && modern ? "\n/*\n//@ sourceMappingURL=[url]\n//# sourceMappingURL=[url]\n*/" :
legacy ? "\n/*\n//@ sourceMappingURL=[url]\n*/" :
modern ? "\n//# sourceMappingURL=[url]" :
null;
module.exports = comment
and this package json:
{
"name": "foo",
"version": "1.0.0",
"main": "index.js"
}
After importing import 'foo'
it into my code, I got the same error!
npm run start
> electron-compile-webpack-bug@1.0.0 start C:\workspace\js\electron-compile-webpack-bug
> electron .
App threw an error during load
C:\workspace\js\electron-compile-webpack-bug\node_modules\foo\index.js:3
const comment = legacy && modern ? "\n/*\n//@ sourceMappingURL=[url]\n//# sourceMappingURL=node_modules\foo\[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\electron-compile-webpack-bug\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\electron-compile-webpack-bug\index.js:3:1)
at Object.<anonymous> (C:\workspace\js\electron-compile-webpack-bug\index.js:73:3)
Notice that it's - again - caused by require-hook callback. Unfortunately I have not figured out yet what it does.
edit:// I think that is the part which is overriden by electron-compilers / babel?
edit:// If the file is not within node_modules, the bug does not appear. I create a new file in the root directory with the same contents as node_modules/foo/index.js
but it compiles down without error.
I think I found the upstream, it's probably this one: https://github.com/babel/babel/issues/4012
Is it possible to passthrough only for some files?
@arekkas Not at the moment. Why do you need to import webpack in your app? That's Odd.
I am building a static site generator based on electron and I use webpack in the production bundle to build the site
That makes sense - the Babel bug linked above has a workaround, you probably have to go with that for now, sorry I don't have a good answer :(
I used electron-compile (with electron-compilers) 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.The error is caused because I am importing webpack 2.x in my electron main thread
import webpack from 'webpack'
. If I remove the import electron-compile works fine.I believe that the issue is somewhere in this package, maybe because babel is iterating over node_modules or something?
This is the error I receive:
When I inspect the code, I see that there is a small difference. Above, the line escapes the last quote:
while in the code, the last quote is not escaped:
Additionally, it seems like the string
node_modules\webpack\lib
was injected.When setting
DEBUG=*
these are the logs:This is an upstream to https://github.com/electron/electron-compile/issues/210