Starting up a web worker in electron seems to yield
worker.4ea33c72.js:1 Uncaught ReferenceError: process is not defined
(anonymous) @ worker.4ea33c72.js:1
I see another closed issue with this error but it seems to be related to electron and web workers in the browser half of the environment.
.tsconfig
{
"compilerOptions": {
"sourceMap": true,
"lib": [ "es2017", "dom" ],
"downlevelIteration": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true
},
"include": [
"index.ts",
"src/**/*.ts"
],
"exclude": [
"node_modules",
"**/*.spec.ts"
]
}
Also, providing absolute paths is the only way plugins will work, because relative ones don't work.
{
"plugins": [
"C:\\Users\\jtenner\\Desktop\\projects\\project-revoluti0n\\babel-plugins\\script-transformer.js",
]
}
I guess if process isn't defined, define it. I don't know where this code is generated, but it's literally the first line of my code for the worker, and I can't get it running.

It's the first line of the generated worker.
No idea.
The code is going to be MIT so I don't mind sharing the entry point.
import config from "../../application.config";
import { IPointClickEvent } from "../events/IPointClickEvent";
import { IPointMoveEvent } from "../events/IPointMoveEvent";
import { IWorkerEvent } from "../events/IWorkerEvent";
import { IInteractionPoint } from "../util";
import { ISprite } from "../view/Sprite";
import { IStageManagerProps, StageManager } from "./StageManager";
const props: IStageManagerProps = {
audioContext: new AudioContext(),
height: config.window.height,
selector: "body",
width: config.window.width,
};
const sm = new StageManager(props);
const worker = new Worker("../worker/index.js");
| Software | Version(s) |
| ---------------- | ---------- |
| Parcel | 1.9.4
| Node | 10.6.0
| npm/Yarn | 1.7.0
| Operating System | Windows
| electron | 2.0.4
| electron-builder | 20.19.2
I have no problem trying to help fix this in any way. Thanks for the help!
I don't think the entrypoint is the issue, as it'll be MIT. Could you share the entire codebase? Ot at least the part with the bug?
Solved the problem.
In your main.js file of your electron environment, you must enable the nodeIntegrationInWorker parameter like this:
mainWindow = new BrowserWindow({
width: config.window.width,
height: config.window.height,
webPreferences: {
nodeIntegrationInWorker: true
},
});
I'm now staring down the barrel of a different problem/error which is great news!
I have the following recommendations/suggestions:
This is out of scope of parcel however you could request electron to show a warning for that
Sent with GitHawk
Okay. If parcel doesn't make assumptions about the environment, can we at least put a line in our documentation where the --target=electron options appears?
Example:
For electron users who want to use workers, please enable the webPreferences: { nodeIntegrationInWorker: true } property when creating your browser window.
It would have saved me at least three hours of headaches.
Feel free to open up a pr in parcel/website repo
Sent with GitHawk
Most helpful comment
Solved the problem.
In your
main.jsfile of yourelectronenvironment, you must enable thenodeIntegrationInWorkerparameter like this:I'm now staring down the barrel of a different problem/error which is great news!
I have the following recommendations/suggestions: