Hi
I use chokidar the file watcher in an Electron app and webpack to build and bundle files.
Its dependency module fsevents was installed successfully.
There is an issue: require('fsevents') in chokidar returned error: "can not find module ."
The following line in fsevents.js
var Native = require(binary.find(path.join(__dirname, 'package.json')))
is converted to var Native = !(function webpackMissingModule() { var e = new Error("Cannot find module \".\""); e.code = 'MODULE_NOT_FOUND'; throw e; }());
I cannot figure out a way to avoid such conversion when requiring dynamic variables.
Any clues and suggestions are welcome.
Notice:
[fsevents] Success: "/Users/icetee/DEV/_incubator/electron-test/node_modules/fsevents/lib/binding/Release/node-v57-darwin-x64/fse.node" already installed
Pass --update-binary to reinstall or --build-from-source to recompile
Solution command :
npm rebuild fsevents --update-binary
But it comes with every install / update package (which uses this package) in Atom (Electron based).
If you're landing here because fsevents was causing our osx signing to fail. Make sure to move it to the devDependencies instead of just dependencies.
If you're not including fsevents directly in your package.json then you'll want to check your yarn.lock or package-lock.json file to see which packages depend on fsevents and make sure to move those to devDependencies as well.
Thanks for the tip @joshuapinter
I don't think this issue should be closed. Unfortunately, the original report is still valid !
Ok, here is how I sorted it out for good !
In package.json :
"optionalDependencies": {
"fsevents": "^1.2.4"
},
In webpack main process build, you need this to prevent webpack from trying to resolve dependencies in a way that doesn't make sense in an Electron runtime context.
You do this by declaring _fsevents_ as external:
module.exports = {
target: 'electron-main',
externals: {
'fsevents': "require('fsevents')",
},
This will not only remove "_Critical dependency: the request of a dependency is an expression_" warnings you might get so far, but it will also ensure that _fsevents_ is imported with a simple... require('fsevents') at run time.
Of course, _fsevents_ must be natively compiled and embedded in Electron.
electron-rebuild -f simply does the trick, but I've found useful to launch it like this:
DEBUG=* electron-rebuild -f ... in order to figure out what's really going on.
Hope it helps someone !
Do you mind providing a bit more detail? Took me forever to track down this osx-sign issue but I'm still not getting it. I use electron-forge and I'm not all that familiar with webpack.
I tried adding that module.exports to a webpack.config.js file but still doesn't fix my signing error.
Most helpful comment
Ok, here is how I sorted it out for good !
In
package.json:In webpack main process build, you need this to prevent webpack from trying to resolve dependencies in a way that doesn't make sense in an Electron runtime context.
You do this by declaring _fsevents_ as external:
This will not only remove "_Critical dependency: the request of a dependency is an expression_" warnings you might get so far, but it will also ensure that _fsevents_ is imported with a simple...
require('fsevents')at run time.Of course, _fsevents_ must be natively compiled and embedded in Electron.
electron-rebuild -fsimply does the trick, but I've found useful to launch it like this:DEBUG=* electron-rebuild -f... in order to figure out what's really going on.Hope it helps someone !