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.

Cannot find module 'electron-publisher-custom', because the package name is already in use in npm

See original GitHub issue
  • Electron-Builder Version: 22.11.8
  • Node Version: 15.3.0
  • Electron Version: 13.1.6
  • Electron Type (current, beta, nightly):

beta

  • Target: win32

I am trying to use custom provider, the publish fails with the following warning:

  ⨯ Cannot find module 'electron-publisher-custom'
Require stack:
- D:\Code\ElectronDemo\node_modules\app-builder-lib\out\publish\PublishManager.js
- D:\Code\ElectronDemo\node_modules\app-builder-lib\out\index.js
- D:\Code\ElectronDemo\node_modules\electron-builder\out\builder.js
- D:\Code\ElectronDemo\node_modules\electron-builder\out\cli\cli.js
- D:\Code\ElectronDemo\node_modules\electron-builder\cli.js  failedTask=build stackTrace=Error: Cannot find module 'electron-publisher-custom' 

i think we should use providerName instead of name when constructing a new instance of a custom publisher,because the package name is already in use in npm,I don’t have permission to publish.

like this:

function requireProviderClass(provider: string, packager: Packager, customProviderName?:string): any | null {
  switch (provider) {
    case "github":
      return GitHubPublisher
    case "bintray":
      return BintrayPublisher
    case "generic":
      return null
    case "s3":
      return S3Publisher
    case "snapStore":
      return SnapStorePublisher
    case "spaces":
      return SpacesPublisher
    default: {
      const name = `electron-publisher-${customProviderName}`
      let module: any = null
      try {
        module = require(path.join(packager.buildResourcesDir, name + ".js"))
      } catch (ignored) {
        console.log(ignored)
      }
      if (module == null) {
        module = require(name)
      }
      return module.default || module
    }
  }
}

or

function requireProviderClass(providerNmae: string, packager: Packager): any | null {
  switch (providerNmae) {
    case "GitHub":
      return GitHubPublisher
    ...
    default: {
      const name = `electron-publisher-${providerNmae}`
      let module: any = null
      try {
        module = require(path.join(packager.buildResourcesDir, name + ".js"))
      } catch (ignored) {
        console.log(ignored)
      }
      if (module == null) {
        module = require(name)
      }
      return module.default || module
    }
  }
}

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6

github_iconTop GitHub Comments

2reactions
ArcherTristercommented, Jul 30, 2021

If we use providerName instead of name,we can publish a custom package to npm, just use it this way, and we don’t need to store electron-publisher-custom.js files under folder resources.

eg:

npm i electron-publisher-xxx -save

publish:
  - provider: custom
    providerName: xxx

electron-builder can’t find electron-publisher-custom.js files will execute the following code

if (module == null) {
        module = require(name)
}
0reactions
stale[bot]commented, Apr 16, 2022

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I resolve "Cannot find module" error using Node.js?
Using npm install installs the module into the current directory only (in a subdirectory called node_modules ). Is app.js located under ...
Read more >
cannot find module [Node npm Error Solved] - freeCodeCamp
I'm getting the error because I'm trying to import the freeCodeCamp icon from the react-icons package, which I don't have installed. import { ......
Read more >
package.json - npm Docs
Description. This document is all you need to know about what's required in your package.json file. It must be actual JSON, not just...
Read more >
pkg - npm
This command line interface enables you to package your Node.js project into an executable that can be run even on devices without Node.js ......
Read more >
Using npm packages in your projects
If you are creating a Node.js module, you can use a package in your module by passing it as an argument to the...
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