PKief / angular-cli-electron

Angular CLI + Electron
https://medium.com/@PhilippKief/angular-desktop-apps-a9ce9e3574e8
48 stars 14 forks source link

Cannot find module '***' [Windows] #5

Open atifkhan161 opened 6 years ago

atifkhan161 commented 6 years ago

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.

PKief commented 6 years ago

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?

atifkhan161 commented 6 years ago

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.

vooft commented 6 years ago

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.