electron-shared-state icon indicating copy to clipboard operation
electron-shared-state copied to clipboard

Requiering `dist/index.cjs.js` result in error "Cannot read properties of undefined (reading 'on')"

Open d-Pixie opened this issue 2 years ago • 1 comments

Using the latest version in an Electron app (electron-forge with webpack). If I import the library it works fine. But I also have to require it in main.js, since it is Common JS, and that results in the above error.

Since one uses the dist/index.mjs.js file and the other the dist/index.cjs.js I suspect something with how the latter is built is amiss.

It could conceivably also be how my project builds, but I donät think so since the error points straight to the file in node_modules.

I could also solve the problem by converting the project to mjs, but I tried that and got stuck 🙂 Too bad that the boilerplate is still in cjs ...

d-Pixie avatar Dec 09 '22 19:12 d-Pixie

Hey, check the /example folder, it uses cjs too with no build tool and it works fine.

I also tried yarn create electron-app my-electron-app --template=webpack with electron-shared-state, and it works fine.

Could you create a minimal repo to reproduce so I can see your build config?

zoubingwu avatar Mar 11 '23 21:03 zoubingwu