Skip to content
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

Problem building multiple mac targets: TypeError: pattern.startsWith is not a function #3012

Closed
paulingalls opened this issue Jun 14, 2018 · 14 comments · Fixed by #5739
Closed

Comments

@paulingalls
Copy link

Electron Builder:

  • 2.15.3:

Electron 2.0.2

Target:

  • dmg,mas:

I'm running into a problem when I try to build for both dmg,zip and mas.

Basically
"target": ["dmg", "zip"] // works
"target": ["mas"] // works
"target": ["mas", "dmg", "zip"] // shows the error below

Let me know if you need more info...

  TypeError: pattern.startsWith is not a function
    at FileMatcher.normalizePattern (/Users/paulingalls/src/fanzo/desktop/ripl-electron/node_modules/electron-builder-lib/src/fileMatcher.ts:42:17)
    at FileMatcher.patterns.map.it (/Users/paulingalls/src/fanzo/desktop/ripl-electron/node_modules/electron-builder-lib/src/fileMatcher.ts:37:54)
    at Array.map (<anonymous>)
    at new FileMatcher (/Users/paulingalls/src/fanzo/desktop/ripl-electron/node_modules/electron-builder-lib/src/fileMatcher.ts:37:39)
    at /Users/paulingalls/src/fanzo/desktop/ripl-electron/node_modules/electron-builder-lib/src/util/AppFileCopierHelper.ts:123:21
    at Generator.next (<anonymous>)
From previous event:
    at _bluebirdLst.default.mapSeries (/Users/paulingalls/src/fanzo/desktop/ripl-electron/node_modules/electron-builder-lib/src/util/AppFileCopierHelper.ts:120:16)
From previous event:
    at /Users/paulingalls/src/fanzo/desktop/ripl-electron/node_modules/electron-builder-lib/src/util/AppFileCopierHelper.ts:120:32
    at Generator.next (<anonymous>)
From previous event:
    at copyNodeModules (/Users/paulingalls/src/fanzo/desktop/ripl-electron/node_modules/electron-builder-lib/out/util/AppFileCopierHelper.js:319:18)
    at /Users/paulingalls/src/fanzo/desktop/ripl-electron/node_modules/electron-builder-lib/src/platformPackager.ts:261:42
    at Generator.next (<anonymous>)
From previous event:
    at then (/Users/paulingalls/src/fanzo/desktop/ripl-electron/node_modules/electron-builder-lib/src/platformPackager.ts:257:14)
From previous event:
    at _computeFileSets (/Users/paulingalls/src/fanzo/desktop/ripl-electron/node_modules/electron-builder-lib/src/platformPackager.ts:258:10)
    at MacPackager.copyAppFiles (/Users/paulingalls/src/fanzo/desktop/ripl-electron/node_modules/electron-builder-lib/src/platformPackager.ts:280:27)
    at /Users/paulingalls/src/fanzo/desktop/ripl-electron/node_modules/electron-builder-lib/src/platformPackager.ts:214:10
    at Generator.next (<anonymous>)
    at runCallback (timers.js:794:20)
    at tryOnImmediate (timers.js:752:5)
    at processImmediate [as _immediateCallback] (timers.js:729:5)
From previous event:
    at MacPackager.doPack (/Users/paulingalls/src/fanzo/desktop/ripl-electron/node_modules/electron-builder-lib/src/platformPackager.ts:162:151)
    at /Users/paulingalls/src/fanzo/desktop/ripl-electron/node_modules/electron-builder-lib/src/macPackager.ts:107:20
    at Generator.next (<anonymous>)
From previous event:
    at MacPackager.pack (/Users/paulingalls/src/fanzo/desktop/ripl-electron/node_modules/electron-builder-lib/src/macPackager.ts:79:95)
    at /Users/paulingalls/src/fanzo/desktop/ripl-electron/node_modules/electron-builder-lib/src/packager.ts:373:24
    at Generator.next (<anonymous>)
    at xfs.stat (/Users/paulingalls/src/fanzo/desktop/ripl-electron/node_modules/fs-extra-p/node_modules/fs-extra/lib/mkdirs/mkdirs.js:56:16)
    at /Users/paulingalls/src/fanzo/desktop/ripl-electron/node_modules/graceful-fs/polyfills.js:287:18
    at FSReqWrap.oncomplete (fs.js:153:5)
From previous event:
    at Packager.doBuild (/Users/paulingalls/src/fanzo/desktop/ripl-electron/node_modules/electron-builder-lib/src/packager.ts:341:39)
    at /Users/paulingalls/src/fanzo/desktop/ripl-electron/node_modules/electron-builder-lib/src/packager.ts:317:52
    at Generator.next (<anonymous>)
    at /Users/paulingalls/src/fanzo/desktop/ripl-electron/node_modules/graceful-fs/graceful-fs.js:99:16
    at /Users/paulingalls/src/fanzo/desktop/ripl-electron/node_modules/graceful-fs/graceful-fs.js:43:10
    at FSReqWrap.oncomplete (fs.js:135:15)
From previous event:
    at Packager._build (/Users/paulingalls/src/fanzo/desktop/ripl-electron/node_modules/electron-builder-lib/src/packager.ts:294:133)
    at /Users/paulingalls/src/fanzo/desktop/ripl-electron/node_modules/electron-builder-lib/src/packager.ts:290:23
    at Generator.next (<anonymous>)
    at runCallback (timers.js:794:20)
    at tryOnImmediate (timers.js:752:5)
    at processImmediate [as _immediateCallback] (timers.js:729:5)
From previous event:
    at Packager.build (/Users/paulingalls/src/fanzo/desktop/ripl-electron/node_modules/electron-builder-lib/src/packager.ts:248:14)
    at /Users/paulingalls/src/fanzo/desktop/ripl-electron/node_modules/electron-builder-lib/src/index.ts:51:40
    at Generator.next (<anonymous>)
From previous event:
    at build (/Users/paulingalls/src/fanzo/desktop/ripl-electron/node_modules/electron-builder-lib/out/index.js:220:17)
    at build (/Users/paulingalls/src/fanzo/desktop/ripl-electron/node_modules/electron-builder/src/builder.ts:234:10)
    at then (/Users/paulingalls/src/fanzo/desktop/ripl-electron/node_modules/electron-builder/src/cli/cli.ts:46:19)
    at <anonymous>
@popod
Copy link
Contributor

popod commented Jun 18, 2018

Can you provide the build section of your package.json please. This works for me with electron-builder 2.15.1.

@paulingalls
Copy link
Author

paulingalls commented Jun 19, 2018

Here is a cauterized version. This version works, as target is set to just dmg & zip. It breaks if I add mas..

Perhaps it is new behavior with 2.15.3...

"build": {
    "appId": "com.appId",
    "productName": "Name",
    "copyright": "Copyright ©2018 ",
    "files": [
      "app/**/*",
      "node_modules/**/*",
      "package.json"
    ],
    "directories": {
      "buildResources": "resources"
    },
    "mac": {
      "category": "public.app-category.business",
      "type": "distribution",
      "target": ["dmg", "zip"]
    },
    "mas": {
      "provisioningProfile": "resources/prod.provisionprofile",
      "entitlements": "resources/entitlements.mas.plist",
      "entitlementsInherit": "resources/entitlements.mas.inherit.plist",
      "type": "distribution"
    },
    "win": {
      "publisherName": "Ripl",
      "target": [
        {
          "target": "nsis-web",
          "arch": [
            "x64",
            "ia32"
          ]
        },
        {
          "target": "appx",
          "arch": [
            "x64",
            "ia32"
          ]
        }
      ]
    },
    "publish": {
      "provider": "s3",
      "bucket": "bucket",
      "region": "us-east-1",
      "path": "path"
    }
  },

@stale
Copy link

stale bot commented Jul 2, 2019

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

@stale stale bot added the backlog label Jul 2, 2019
@stale stale bot closed this as completed Jul 9, 2019
@Aarbel
Copy link

Aarbel commented Sep 17, 2019

Any news about this problem & solutions to fix it ? I'm on electron-builder v20.44.4

@MartinBarker
Copy link

same issue

@mmaietta
Copy link
Collaborator

@MartinBarker, with latest v22.10.5?

@mifi
Copy link
Contributor

mifi commented Mar 25, 2021

Downgrade to v22.10.4 worked for me

Edit: in 22.10.4 it still gives the error, but only if run with DEBUG=electron-builder:

(node:35721) PromiseRejectionHandledWarning: Promise rejection was handled asynchronously (rejection id: 1)
  ⨯ pattern.startsWith is not a function  stackTrace=
                                            TypeError: pattern.startsWith is not a function
                                                at FileMatcher.normalizePattern (node_modules/app-builder-lib/src/fileMatcher.ts:58:17)
                                                at node_modules/app-builder-lib/src/fileMatcher.ts:53:54
                                                at Array.map (<anonymous>)
                                                at new FileMatcher (node_modules/app-builder-lib/src/fileMatcher.ts:53:39)
                                                at computeNodeModuleFileSets (node_modules/app-builder-lib/src/util/appFileCopier.ts:197:21)
                                                at node_modules/app-builder-lib/src/platformPackager.ts:306:36
                                                at async Promise.all (index 0)
                                                at AsyncTaskManager.awaitTasks (node_modules/builder-util/src/asyncTaskManager.ts:65:25)
                                                at MacPackager.doPack (node_modules/app-builder-lib/src/platformPackager.ts:219:5)

I get the error when running npx electron-builder --mac. This results in a broken dist/mas build containing only Electron.app, LICENSE and LICENSES.chromium.html, but dist/mac seems to be successfully built.

When instead running npx electron-builder --mac -m dmg it successfully builds without any error.

@mmaietta mmaietta reopened this Mar 25, 2021
@stale stale bot removed the backlog label Mar 25, 2021
@mifi
Copy link
Contributor

mifi commented Mar 26, 2021

I added a console.log(from, to, patterns) before this line:

this.patterns = asArray(patterns).map(it => this.normalizePattern(it))

It resulted in many lines like this:

.../lossless-cut .../lossless-cut/dist/mac/Electron.app/Contents/Resources/app/node_modules [
  '**/*',
  'build/**/*',
  'build/**/*',
  '!node_modules/ffmpeg-ffprobe-static/ffmpeg',
  '!node_modules/ffmpeg-ffprobe-static/ffprobe'
]

Then right before pattern.startsWith is not a function came this line:

.../lossless-cut/node_modules/agent-base .../lossless-cut/dist/mas/Electron.app/Contents/Resources/app/node_modules/agent-base/node_modules [
  '**/*',
  'build/**/*',
  'build/**/*',
  '!node_modules/ffmpeg-ffprobe-static/ffmpeg',
  '!node_modules/ffmpeg-ffprobe-static/ffprobe',
  [
    '**/*',
    'build/**/*',
    'build/**/*',
    '!node_modules/ffmpeg-ffprobe-static/ffmpeg',
    '!node_modules/ffmpeg-ffprobe-static/ffprobe'
  ]
]

This leads me to believe there is a bug somewhere lower in the call stack where instead of combining two arrays, some code is instead adding the second array as an item in the base array. But only when multiple targets are running...

@mifi
Copy link
Contributor

mifi commented Mar 26, 2021

Seems like this is an old bug. Happened it 2019 also: #4204 (comment)

Maybe it was just hidden all along and just now started to crash the build in the latest version

@gaodeng
Copy link
Contributor

gaodeng commented Mar 26, 2021

I've run into this problem before. I can't quite remember the root cause of the problem right now. But I'll submit a PR later if needed

@buu700
Copy link

buu700 commented May 9, 2021

This is the error I'm getting on macOS (Big Sur 11.3.1, arm64) with Node 14.16.1:

TypeError: pattern.startsWith is not a function
    at FileMatcher.normalizePattern (/Users/buu700/cyph/prod/app/cordova-build/node_modules/app-builder-lib/src/fileMatcher.ts:59:17)
    at /Users/buu700/cyph/prod/app/cordova-build/node_modules/app-builder-lib/src/fileMatcher.ts:53:54
    at Array.map (<anonymous>)
    at new FileMatcher (/Users/buu700/cyph/prod/app/cordova-build/node_modules/app-builder-lib/src/fileMatcher.ts:53:39)
    at computeNodeModuleFileSets (/Users/buu700/cyph/prod/app/cordova-build/node_modules/app-builder-lib/src/util/appFileCopier.ts:197:21)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at /Users/buu700/cyph/prod/app/cordova-build/node_modules/app-builder-lib/src/platformPackager.ts:306:36
    at async Promise.all (index 0)
    at AsyncTaskManager.awaitTasks (/Users/buu700/cyph/prod/app/cordova-build/node_modules/builder-util/src/asyncTaskManager.ts:65:25)
    at MacPackager.doPack (/Users/buu700/cyph/prod/app/cordova-build/node_modules/app-builder-lib/src/platformPackager.ts:219:5)
    at MacPackager.doPack (/Users/buu700/cyph/prod/app/cordova-build/node_modules/app-builder-lib/src/macPackager.ts:103:9)
    at MacPackager.pack (/Users/buu700/cyph/prod/app/cordova-build/node_modules/app-builder-lib/src/macPackager.ts:158:9)
    at Packager.doBuild (/Users/buu700/cyph/prod/app/cordova-build/node_modules/app-builder-lib/src/packager.ts:434:9)
    at executeFinally (/Users/buu700/cyph/prod/app/cordova-build/node_modules/builder-util/src/promise.ts:12:14)
    at Packager._build (/Users/buu700/cyph/prod/app/cordova-build/node_modules/app-builder-lib/src/packager.ts:369:31)
    at Packager.build (/Users/buu700/cyph/prod/app/cordova-build/node_modules/app-builder-lib/src/packager.ts:333:12)
    at executeFinally (/Users/buu700/cyph/prod/app/cordova-build/node_modules/builder-util/src/promise.ts:12:14)

It looks like the immediate issue is that an empty array is being passed in to normalizePattern rather than a string.

Edit: Applying #5739 as a patch with patch-package worked for me. Thanks @gaodeng!

@mmaietta
Copy link
Collaborator

mmaietta commented May 9, 2021

Thanks for verifying that @buu700.
I've approved and merged the PR, it'll make our next release.

@gurpreetsingh41333
Copy link

This is the error I'm getting on macOS (Big Sur 11.3.1, arm64) with Node 14.16.1:

TypeError: pattern.startsWith is not a function
    at FileMatcher.normalizePattern (/Users/buu700/cyph/prod/app/cordova-build/node_modules/app-builder-lib/src/fileMatcher.ts:59:17)
    at /Users/buu700/cyph/prod/app/cordova-build/node_modules/app-builder-lib/src/fileMatcher.ts:53:54
    at Array.map (<anonymous>)
    at new FileMatcher (/Users/buu700/cyph/prod/app/cordova-build/node_modules/app-builder-lib/src/fileMatcher.ts:53:39)
    at computeNodeModuleFileSets (/Users/buu700/cyph/prod/app/cordova-build/node_modules/app-builder-lib/src/util/appFileCopier.ts:197:21)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at /Users/buu700/cyph/prod/app/cordova-build/node_modules/app-builder-lib/src/platformPackager.ts:306:36
    at async Promise.all (index 0)
    at AsyncTaskManager.awaitTasks (/Users/buu700/cyph/prod/app/cordova-build/node_modules/builder-util/src/asyncTaskManager.ts:65:25)
    at MacPackager.doPack (/Users/buu700/cyph/prod/app/cordova-build/node_modules/app-builder-lib/src/platformPackager.ts:219:5)
    at MacPackager.doPack (/Users/buu700/cyph/prod/app/cordova-build/node_modules/app-builder-lib/src/macPackager.ts:103:9)
    at MacPackager.pack (/Users/buu700/cyph/prod/app/cordova-build/node_modules/app-builder-lib/src/macPackager.ts:158:9)
    at Packager.doBuild (/Users/buu700/cyph/prod/app/cordova-build/node_modules/app-builder-lib/src/packager.ts:434:9)
    at executeFinally (/Users/buu700/cyph/prod/app/cordova-build/node_modules/builder-util/src/promise.ts:12:14)
    at Packager._build (/Users/buu700/cyph/prod/app/cordova-build/node_modules/app-builder-lib/src/packager.ts:369:31)
    at Packager.build (/Users/buu700/cyph/prod/app/cordova-build/node_modules/app-builder-lib/src/packager.ts:333:12)
    at executeFinally (/Users/buu700/cyph/prod/app/cordova-build/node_modules/builder-util/src/promise.ts:12:14)

It looks like the immediate issue is that an empty array is being passed in to normalizePattern rather than a string.

Edit: Applying #5739 as a patch with patch-package worked for me. Thanks @gaodeng!

can you please add the steps on how you resolved this issue?

@buu700
Copy link

buu700 commented May 21, 2021

Sure, just use patch-package with the attached patch.

Edit: Or just use the current stable version of builder-util (22.11.5), which already has the fix included.

builder-util+22.10.5.patch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
9 participants