Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot install fsevents with Electron as runtime #131

Closed
bpasero opened this issue May 3, 2016 · 22 comments
Closed

Cannot install fsevents with Electron as runtime #131

bpasero opened this issue May 3, 2016 · 22 comments

Comments

@bpasero
Copy link

bpasero commented May 3, 2016

Using latest fsevents that brings node-pre-gyp I am no longer able to install this dependency (via chokidar) into VS Code that leverages Electron as framework.

Our npm script for installation configures some environment variables to pick up the correct headers for the embedded node.js version within Electron:

npm_config_disturl=https://atom.io/download/atom-shell \
npm_config_target=$ELECTRON_VERSION \

Running this via npm install yields:

> fsevents@1.0.12 install /Users/bpasero/Development/monaco/node_modules/fsevents
> node-pre-gyp install --fallback-to-build

node-pre-gyp ERR! install error 
node-pre-gyp ERR! stack Error: Unsupported target version: 0.37.6
node-pre-gyp ERR! stack     at get_runtime_abi (/Users/bpasero/Development/monaco/node_modules/node-pre-gyp/lib/util/versioning.js:156:23)
node-pre-gyp ERR! stack     at Object.module.exports.evaluate (/Users/bpasero/Development/monaco/node_modules/node-pre-gyp/lib/util/versioning.js:277:19)
node-pre-gyp ERR! stack     at install (/Users/bpasero/Development/monaco/node_modules/node-pre-gyp/lib/install.js:138:31)
node-pre-gyp ERR! stack     at Object.self.commands.(anonymous function) [as install] (/Users/bpasero/Development/monaco/node_modules/node-pre-gyp/lib/node-pre-gyp.js:48:37)
node-pre-gyp ERR! stack     at run (/Users/bpasero/Development/monaco/node_modules/node-pre-gyp/bin/node-pre-gyp:79:30)
node-pre-gyp ERR! stack     at Object.<anonymous> (/Users/bpasero/Development/monaco/node_modules/node-pre-gyp/bin/node-pre-gyp:131:1)
node-pre-gyp ERR! stack     at Module._compile (module.js:413:34)
node-pre-gyp ERR! stack     at Object.Module._extensions..js (module.js:422:10)
node-pre-gyp ERR! stack     at Module.load (module.js:357:32)
node-pre-gyp ERR! stack     at Function.Module._load (module.js:314:12)
node-pre-gyp ERR! System Darwin 15.4.0
node-pre-gyp ERR! command "/usr/local/bin/node" "/Users/bpasero/Development/monaco/node_modules/.bin/node-pre-gyp" "install" "--fallback-to-build"
node-pre-gyp ERR! cwd /Users/bpasero/Development/monaco/node_modules/fsevents
node-pre-gyp ERR! node -v v5.10.0
node-pre-gyp ERR! node-pre-gyp -v v0.6.27
node-pre-gyp ERR! not ok 
Unsupported target version: 0.37.6
npm WARN install:fsevents@1.0.12 fsevents@1.0.12 install: `node-pre-gyp install --fallback-to-build`
npm WARN install:fsevents@1.0.12 Exit status 1

This basically means we cannot update to newer versions of chokidar currently.

@bnoordhuis
Copy link
Contributor

That's a node-pre-gyp issue, not a fsevents issue. Presumably you didn't pass --runtime=electron to npm and/or node-pre-gyp.

@bpasero
Copy link
Author

bpasero commented May 3, 2016

@bnoordhuis thanks, specifying runtime seems to work. Is there a way to configure this with an environment variable instead of passing it to npm as argument?

@bpasero bpasero closed this as completed May 3, 2016
@bnoordhuis
Copy link
Contributor

I'm reasonably sure export npm_config_runtime=electron should do it.

@bpasero bpasero reopened this May 3, 2016
@bpasero
Copy link
Author

bpasero commented May 3, 2016

While I can install now, requiring fsevents from chokidar fails with the following error:

{ [Error: Cannot find module '/Users/bpasero/Development/monaco/node_modules/fsevents/lib/binding/Release/node-v47-darwin-x64/fse.node'] code: 'MODULE_NOT_FOUND' }

I don't think in the older chokidar (without node-pre-gyp) did we have such a long path to require the fse.node. It just lives inside build/Release/fse.node

@es128
Copy link
Contributor

es128 commented May 3, 2016

Give this a try:

FSEVENTS_BUILD_FROM_SOURCE=true npm i strongloop/fsevents#build-from-source

@bpasero
Copy link
Author

bpasero commented May 3, 2016

@es128 is the npm i strongloop/fsevents#build-from-source meant to be part of the variable?

@bpasero
Copy link
Author

bpasero commented May 3, 2016

Now I am getting a folder after installation electron-v0.37-darwin-x64 but the lookup is actually trying to find it at node-v47-darwin-x64. Do I have to set another environment variable?

@es128
Copy link
Contributor

es128 commented May 3, 2016

No it's not part of the variable, I'm just setting it transiently as I run the command. export FSEVENTS_BUILD_FROM_SOURCE=true should be fine too.

Not sure on the other part. Perhaps try deleting npm_config_runtime=electron from your env when trying this method.

@bpasero
Copy link
Author

bpasero commented May 3, 2016

Unfortunatley that returns the "Error: Unsupported target version: 0.37.6" error.

@es128
Copy link
Contributor

es128 commented May 3, 2016

Looks like I need to bump up the node-pre-gyp dependency. Really annoying how it needs to explicitly keep track of all possible versions

@es128
Copy link
Contributor

es128 commented May 3, 2016

I updated the branch, give it a try

@bpasero
Copy link
Author

bpasero commented May 3, 2016

@es128 yeah it would be nice if there was a way to tell npm to ignore all of node-pre-gyp if a certain environment variable is set. In my case I am totally fine compiling fsevents each time.

Which branch are we talking about for me to try?

@es128
Copy link
Contributor

es128 commented May 3, 2016

build-from-source

The npm install command I had given you earlier was pulling it from there

@bpasero
Copy link
Author

bpasero commented May 3, 2016

@es128 ok is your change having an impact on where the fse.node ends up? Now I am a bit confused if I should still use the runtime option :)

@es128
Copy link
Contributor

es128 commented May 3, 2016

node-pre-gyp changes where the binary goes. What I did was wire node-pre-gyp's --build-from-source option to the env variable so that you're not dependent on the pre-build binaries.

I tried cutting out the node-pre-gyp command entirely, but the bindings.gyp has incompatible changes. Maybe I need to keep trying that route to let it completely defer to node's native build handling.

We could maintain and publish a fork I guess, but then we'd need the same for chokidar. Would be nice if npm allowed users control over swapping out compatible subdependencies

@bpasero
Copy link
Author

bpasero commented May 3, 2016

@es128 ok here are the results:

with npm_config_runtime=electron

  SOLINK_MODULE(target) Release/.node
  CXX(target) Release/obj.target/fse/fsevents.o
  SOLINK_MODULE(target) Release/fse.node
  COPY /Users/bpasero/Development/Microsoft/monaco/node_modules/fsevents/lib/binding/Release/electron-v0.37-darwin-x64/fse.node
  TOUCH Release/obj.target/action_after_build.stamp

=> fse.node ends up in electron-v0.37-darwin-x64
=> it fails to load because the folder is expected to be node instead of electron

without npm_config_runtime=electron

it fails to install due to:

node-pre-gyp ERR! UNCAUGHT EXCEPTION 
node-pre-gyp ERR! stack Error: Unsupported target version: 0.37.6

Good news is: When I manually rename electron-v0.37-darwin-x64 to node-v0.37-darwin-x64 fsevents works with Electron, so it seems a matter of making that lookup work properly.

@es128
Copy link
Contributor

es128 commented May 3, 2016

Both conditions seem like bugs in node-pre-gyp tbh. @springmeyer could you take a look please?

@es128
Copy link
Contributor

es128 commented May 3, 2016

@bpasero you could also potentially pinch your nose and solve this with your own workaround by scripting the rename of the target dir

@springmeyer
Copy link

Just seeing this. Tied up in a few meetings right now but will digest this and try to help as soon as I can.

@hedefalk
Copy link

+1

I'm having lots of related issues using apm which just wraps npm:

atom/apm#531
hedefalk/apm@454b237

Feels like there's a lot of confusion on node version vs electron version. Currently, I cannot use my own package under atom because it uses chokidar -> fsevents. Atom refuses to load it until I can rebuild for electron but I simply cannot figure out how to do it right now.

@bumpmann
Copy link

This helped me a lot: http://electron.atom.io/docs/tutorial/using-native-node-modules/

# Electron's version.
export npm_config_target=1.2.3
# The architecture of Electron, can be ia32 or x64.
export npm_config_arch=x64
# Download headers for Electron.
export npm_config_disturl=https://atom.io/download/atom-shell
# Tell node-pre-gyp that we are building for Electron.
export npm_config_runtime=electron
# Tell node-pre-gyp to build module from source code.
export npm_config_build_from_source=true
# Install all dependencies, and store cache to ~/.electron-gyp.
HOME=~/.electron-gyp npm install

n-riesco added a commit to n-riesco/plotly-database-connector that referenced this issue Aug 28, 2017
@dperetti
Copy link

I've spent hours sorting this out, and it's pretty simple once you get it.
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 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants