angular-cli-electron icon indicating copy to clipboard operation
angular-cli-electron copied to clipboard

Cannot find module '***' [Windows]

Open atifkhan161 opened this issue 7 years ago • 3 comments

I'm building an app on windows. The app builds successfully and while running app gives the error "Cannot find module "express". Copying node_modules folder inside resource/app solves the problem. Dependency saved in package.json is not copied at the time of packaging.

atifkhan161 avatar May 10 '18 12:05 atifkhan161

I'm not sure if I understood you correctly. If you want to package the electron application then you run the command e.g. npm run package:win. This command includes a compilation of all angular files to the dist-folder. So now all required dependencies are part of the vendor.bundle.js file in the dist folder. The node_modules are not required anymore to run the application from the dist folder. Finally the electron-packager uses all files from the dist folder to create an executable e.g. "*.exe"-file in the packages folder.

I tried to add some external library to my application, bundled everything to this dist folder and created the packaged files. The command npm run package:win is all I used here and everything worked fine.

I was wondering if you use some direct paths to the node_modules folder in your app? Normally every module should be imported like import * as xyz from 'xyz' right?

PKief avatar May 11 '18 07:05 PKief

Problem is with node modules like express, axios etc. This dependency is mentioned in the package.json file but is not copied to resources folder.

atifkhan161 avatar May 14 '18 06:05 atifkhan161

The problem in node-only modules, that are not (or can not be) referenced from frontend source files. I believe that angular-cli just ignores them. Maybe migrating from electron-packager to something more sophisticated would help.

vooft avatar Sep 27 '18 01:09 vooft