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
"Uncaught Error: Cannot find module" when using asar with native modules #217
Comments
It's most likely that your module is not getting found by node/npm. I have some docs on how this works here: https://github.com/maxogden/art-of-node#how-require-works. Keep trying until it works, I don't think anyone has reported this particular issue before so it's likely something with your setup. |
Thanks @maxogden. I'm going to drum up a simple testcase. I discovered module.paths.push, but it was crunch time and my approach was a lot of spray n' pray. Back to you soon. |
I'm facing the same issue. I have an Electron app which loads a local Express server. The page loads a single Javascript file.
On Ubuntu this works fine with Other than the Express server everything is pretty standard. I'm only trying to load I should note it fails with and without asar. I'm not sure if this is a bug with Electron, Electron Packager, or I'm just doing something wrong. I'd like to think Additional info: Electron version: 0.36.2 (electron-prebuilt) |
Ok, so I've done a little experimenting and this is what I've come up with:
Ubuntu ( There's probably a less messy approach, but this is the only thing I've found which works. Hope this helps someone. |
So where is the request module actually, relative to your application, and which of those module.paths.push is the one finding it? I think this information will help the devs. |
It depends on how I'm running the app. Without the first line The request module is located (when built) at |
After I package with electron-packager, I run packaged app it tells me "can't find module". But if I run as "electron ." it works perfectly. Without asar, "electron /path/to/packaged/app/source" works but directly run packaged app, it fails. Don't know why... |
Same for me. Electron 0.37.2 |
Could the people who have this problem please do the following:
|
I'm also getting this issue here is a very simple example of the issue: npm -v = 3.3.12 |
same error here, I'm using electron-packager 6.0 and eletron 0.37.5 |
A solution for me is to install the required node module in the same directory as the electron.js file. |
Here's what i did for electron 0.37.7 and electron-builder 3.11.0
This works on all platforms. |
A note for potentially confused travellers. Ensure you're not using --ignore="something-that-will-match-a-module-folder-name-as-well-as-what-you-meant-to-ignore". |
I had the same issue, none of the suggestions mentioned above worked for me. The solution was to package my app under a windows virtual machine running on my mac, and everything worked seamlessly. |
Rather than argue about if it works or not could the electron-quick-start package be updated to include lodash and/or jquery so that we have at least one working example of imported libraries. |
@rodhoward if you'd like to request that, you probably want to do so at that repository - you'll likely get a better answer there. |
I now have this issue too. It has only happened with a recent module I've installed: I extracted the created I have checked and I've not got any ignores anywhere. My app runs perfectly fine from the command line before being packaged. |
adding a native module, |
Same for me with |
for those having this issue with a native module, i've had some help and am making some headway on this issue. it appears to be (at least, in my case) because of a dll required by the native module not being found after the application is packaged. I created a folder, dropped the dll in it and added it to my PATH, the asar-packed application loads fine subsequently. This is obviously not a solution that will help redistributing the application, but a step further nonetheless. |
Update: including the dll in the base electron app dir was sufficient for electron to find it
|
OK, I've gathered enough information about this issue. For a lot of people commenting, the problem lies in using the
|
I have the same issue and not using asar didn't help .. |
If #217 (comment) does not help your issue, please follow the instructions in #217 (comment). Otherwise, it's very difficult to figure out what your specific problem may be. |
I tried to make a simple project here. I just added ursa native module and it just doesnt wok : A dynamic link library (DLL) initialization routine failed . |
@RilRil Are you going to use electron-packager directly or electron-builder, is your project answer to electron-userland/electron-builder#598 (comment) ? If you still use electron-builder, "and it just doesn't wok" — on Surface or on your machine? |
I'm not sure why you're using
You mean |
i use nightmarejs to scrap the site, and the scraped data is used for calculation.
|
It doesn't feel right to have to run another Electron instance just to scrape data from a site. However, there seems to be problems with using a single Electron binary. But again, this is offtopic for this issue. As I said earlier, a minimal testcase would be greatly appreciated. |
I have an Electron app that I want to generate another Electron app. The idea is the user inputs images and text using the master app and then can press a button to generate an exe/app file to distribute. I've created a test case to illustrate. I've only created this for darwin x64 right now. To recreate the issue clone repo and npm install in both the root folder and the app folder. Test in development mode using command But if you build the master app using these parameters: |
@pilar1347 this is a different error than the issue this one is about, could you please file a separate issue? (Making sure you read our docs on filing bugs and follow the directions in the GitHub issue template) It would be much appreciated. |
I think I'm going to close this particular issue because there's already one major answer in here and there are way too many different kinds of problems to get a coherent answer for all of them. IF YOU HAVE THIS PROBLEM
|
package.json won't work
package.json works
it looks like that electron-packager looks up dependencies field to pack rather than devDependencies |
From the README:
|
I found the proper solution was to migrate the dependency I wanted to be packaged with the application to a separate "dependencies" node in the packages.config. electron-packager by default will remove the modules listed in the devDependencies section. Hope it helps! |
Strange that this got closed before a solution was posted, but codyborn above hits it: By default, nothing in your node_modules folder will be copied to your final package. You need to add a "dependencies" section to your package.json that explicitly lists everything in your node_modules folder. You also need to dig in to each of those dependencies and fish out a version number to add as well. Like this:
I have no idea why this is not mentioned anywhere in the packaging docs, as it seems to me to be the most important piece of information. As this issue shows, your app simply won't work if you don't do this. |
This is not true. I'm not sure how you arrived at this conclusion. You contradict this statement in your next sentence.
It's implied in the example in the README:
If you think this is not explicit enough, I am happy to review pull requests to make it more obvious. |
I ran into this issue while rebuilding edge.js for electron. Ended up that I was missing the See Error: The specified module could not be found for more details. Thanks for the hint @leshow! |
Had to do this to build Hain as well - surprising we don't have a better solution for this... |
@jasonkester thanks man... you saved my day! |
I solved this issue by adding the dependency to the configuration file. |
I figured out the reason for my issue and the solution. |
I encountered the same problem. But I realised I was using gulp browserify and sending my app to dist/main.min.js.... then have electron.js etc on the root folder. With this bundled, electron cannot find node_modules, because it does not exist. be careful of this. |
Following on from codyborn's and jasonkester's comments above, I think the docs on electron-builder and electron-packager should explicitly advise that things in node_modules that are not added to the dependencies field in package.json will not necessarily end up in the asar file. |
am getting the same err : "can't find module mysql2", am using --ignore=node_modules to ignore node_modules and that's why am getting this err, is there a way to fix this ? |
I have a require('my-module') in a renderer js file. It lives in my-app/node_modules (though I've tried putting it in my-app/.)
It works fine when I run electron . from my-app.
However, once packaged for win32 (created on Ubuntu 14.04), on launch of the .exe I see "Uncaught Error: Cannot find module my-module" in the browser/devtools console.
I've tried require('./my-module')
Am I doing something wrong?
This is with electron 0.36.0, npm-packager 5.1.1
The text was updated successfully, but these errors were encountered: