question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

electron:build command does not copy project package.json - no node modules installed

See original GitHub issue

When running electron:build, the project package.json in the root directory is not copied to the dist_electron/bundled folder and no dependencies are installed. Running the built executable results in a lot of module <name> not found errors in the console.

Steps to reproduce the behavior:

  1. Create a new Vue 2 project with the Vue CLI -> vue create <name>
  2. Add this plugin as per the docs -> vue add electron-builder
  3. Install any node package. For example, yarn add node-fetch
  4. Use this package in any of the source files.
  5. Build the app with yarn electron:build
  6. Run the built .exe and check the console. You will see a missing module for that package error. To further verify this, extracting the app.asar in the dist_electron/win-unpacked/resources folder and opening the output folder will show you none of your installed node modules in the dependencies section of your package.json are copied over.

Expected behavior All packages in the dependencies section of the project package.json should be copied over when building the project.

Environment:

  • Windows 10
  • Yarn (but same problem with NPM)
  • “vue-cli-plugin-electron-builder”: “~2.0.0-rc.6”
  • “electron”: “^11.0.0”

Additional context I original encountered this error in a project I had been working on for months and it appeared within the last couple days. Tried this with just a basic Vue project created with the CLI and only modified the background.js file to use the node-fetch package I had installed. Same problem.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
nklaymancommented, Mar 4, 2021

Yeah, you should use es6 import statements actually. Webpack automatically bundles all your deps together for you.

1reaction
nklaymancommented, Mar 4, 2021

Try adding a vue.config.js file with this in it:

module.exports = {
  pluginOptions: {
    electronBuilder: {
      externals: ['node-fetch']
    }
  }
}

See the docs on native modules for more details on the externals property.

Read more comments on GitHub >

github_iconTop Results From Across the Web

npm - Electron-Builder does not copy node_modules into my ...
I have an electron app with the following structure - dist | - index.html | - node_modules | - nm (is an exact...
Read more >
Cannot find module after installing @electron/build-tools on Arch
I just ran npm install -g @electron/build-tools on Arch LInux and got this error after rehashing in zsh and running e init --root=~/electron...
Read more >
Packaging Electron (Nodejs) Application (along with Flask ...
... of npm. The package can be installed using the following command: ... This gets covered when the project is initiated with package.json....
Read more >
Common Configuration - electron-builder
in the package.json file of your project using the build key on the top level: ... If you want to use js file,...
Read more >
Manage npm packages - Visual Studio (Windows)
json file, you can add one to enable npm support by adding a package.json file to the project. If you don't have Node.js...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found