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

Missing dependency [email protected] when building with electron-builder included #4366

Closed
mbvs opened this issue Oct 29, 2019 · 1 comment · Fixed by #4371
Closed

Missing dependency [email protected] when building with electron-builder included #4366

mbvs opened this issue Oct 29, 2019 · 1 comment · Fixed by #4371

Comments

@mbvs
Copy link

mbvs commented Oct 29, 2019

  • electron-builder Version: 21.2.0
  • node Version: v10.16.3
  • npm Version: 6.12.0
  • target: Linux / macOs

We have an app where we have dependencies to electron-builder (to build custom configured apps out of the app) and Express.

After building the app all runs fine.

After packaging the installer the app crashes cause of an unmet dependency in the packaged app:

TypeError: Cannot read property 'lookup' of undefined
    at ServerResponse.header (/tmp/.mount_targetmteASa/resources/app/node_modules/express/lib/response.js:766)
    at ServerResponse.json (/tmp/.mount_targetmteASa/resources/app/node_modules/express/lib/response.js:264)
    at Object.sendError (/tmp/.mount_targetmteASa/resources/app/node_modules/@rsi/server/dist/utils/helpers.js:559)
    at /tmp/.mount_targetmteASa/resources/app/node_modules/@rsi/server/dist/base.server.js:185
    at Layer.handle [as handle_request] (/tmp/.mount_targetmteASa/resources/app/node_modules/express/lib/router/layer.js:95)
    at trim_prefix (/tmp/.mount_targetmteASa/resources/app/node_modules/express/lib/router/index.js:317)
    at /tmp/.mount_targetmteASa/resources/app/node_modules/express/lib/router/index.js:284
    at param (/tmp/.mount_targetmteASa/resources/app/node_modules/express/lib/router/index.js:354)
    at param (/tmp/.mount_targetmteASa/resources/app/node_modules/express/lib/router/index.js:365)
    at Function.process_params (/tmp/.mount_targetmteASa/resources/app/node_modules/express/lib/router/index.js:410)

'lookup' is a method of the express dependency [email protected]

issuing nmp list mime in linux-unpacked/resources/app gives:

├─┬ [email protected]
│ └─┬ [email protected]
│   └─┬ [email protected]
│     └── [email protected] 
├─┬ [email protected]
│ └─┬ [email protected]
│   └── UNMET DEPENDENCY [email protected]
└── [email protected]  extraneous

The problem occurs both when building under Ubuntu 18.04 and MacOS 10.14.5
Any suggestions?

@da-mkay
Copy link
Contributor

da-mkay commented Oct 29, 2019

We faced the same issue today, but it is not especially related to the mime package. We digged deeper in the electron-builder code and noticed that when copying node_modules to the final build, some modules may be overridden if we have the case of nested node_modules.

I uploaded an example project to reproduce the problem here:
https://github.com/da-mkay/electron-builder-bug-example

The repo containrs a monorepo-like project structure where we have a root package.jsonfor all the modules in the monorepo and a separate package.json inside the electron-app folder which should be used by the electron-builder.

You can see two dependencies: mime version 2.4.4 and express which itself has a dependency to send which depends on mime, but version 1.6.x. Thus, when running npm i you end up with nested node_modules folders containing both mime versions.

Now, when building the electron package (npm run build) you end up with a mixed-up mime-folder inside the node_modules folder. This is because electron-builder copies both mime folders to the same destination, finally mixing up the files of the two versions. I verified this by adding logging to the copy-functions in the builder-util package. From the logs below you can see that first the contents of one mime folder is copied and then the other one, but in both cases the same destination folder is used, eventually leading to a non-working app, because the two versions are incompatible.

Copy from:  <projectDir>/node_modules/mime/.eslintrc.json
Copy to:    <projectDir>/dist/out/mac/Electron.app/Contents/Resources/app/node_modules/mime/.eslintrc.json
Copy from:  <projectDir>/node_modules/mime/CONTRIBUTING.md
Copy to:    <projectDir>/dist/out/mac/Electron.app/Contents/Resources/app/node_modules/mime/CONTRIBUTING.md
Copy from:  <projectDir>/node_modules/mime/LICENSE
Copy to:    <projectDir>/dist/out/mac/Electron.app/Contents/Resources/app/node_modules/mime/LICENSE
Copy from:  <projectDir>/node_modules/mime/Mime.js
Copy to:    <projectDir>/dist/out/mac/Electron.app/Contents/Resources/app/node_modules/mime/Mime.js
Copy from:  <projectDir>/node_modules/mime/cli.js
Copy to:    <projectDir>/dist/out/mac/Electron.app/Contents/Resources/app/node_modules/mime/cli.js
Copy from:  <projectDir>/node_modules/mime/index.js
Copy to:    <projectDir>/dist/out/mac/Electron.app/Contents/Resources/app/node_modules/mime/index.js
Copy from:  <projectDir>/node_modules/mime/lite.js
Copy to:    <projectDir>/dist/out/mac/Electron.app/Contents/Resources/app/node_modules/mime/lite.js
Copy from:  <projectDir>/node_modules/mime/types/other.js
Copy to:    <projectDir>/dist/out/mac/Electron.app/Contents/Resources/app/node_modules/mime/types/other.js
Copy from:  <projectDir>/node_modules/mime/types/standard.js
Copy to:    <projectDir>/dist/out/mac/Electron.app/Contents/Resources/app/node_modules/mime/types/standard.js
Copy from:  <projectDir>/node_modules/mime/src/README_js.md
Copy to:    <projectDir>/dist/out/mac/Electron.app/Contents/Resources/app/node_modules/mime/src/README_js.md
Copy from:  <projectDir>/node_modules/mime/src/benchmark.js
Copy to:    <projectDir>/dist/out/mac/Electron.app/Contents/Resources/app/node_modules/mime/src/benchmark.js
Copy from:  <projectDir>/node_modules/mime/package.json
Copy to:    <projectDir>/dist/out/mac/Electron.app/Contents/Resources/app/node_modules/mime/package.json
Copy from:  <projectDir>/node_modules/mime/src/build.js
Copy to:    <projectDir>/dist/out/mac/Electron.app/Contents/Resources/app/node_modules/mime/src/build.js
Copy from:  <projectDir>/node_modules/mime/src/test.js
Copy to:    <projectDir>/dist/out/mac/Electron.app/Contents/Resources/app/node_modules/mime/src/test.js
Copy from:  <projectDir>/node_modules/mime/.github/ISSUE_TEMPLATE.md
Copy to:    <projectDir>/dist/out/mac/Electron.app/Contents/Resources/app/node_modules/mime/.github/ISSUE_TEMPLATE.md
Copy from:  <projectDir>/node_modules/mime/.github/PULL_REQUEST_TEMPLATE.md
Copy to:    <projectDir>/dist/out/mac/Electron.app/Contents/Resources/app/node_modules/mime/.github/PULL_REQUEST_TEMPLATE.md
Copy from:  <projectDir>/node_modules/send/node_modules/mime/LICENSE
Copy to:    <projectDir>/dist/out/mac/Electron.app/Contents/Resources/app/node_modules/mime/LICENSE
Copy from:  <projectDir>/node_modules/send/node_modules/mime/cli.js
Copy to:    <projectDir>/dist/out/mac/Electron.app/Contents/Resources/app/node_modules/mime/cli.js
Copy from:  <projectDir>/node_modules/send/node_modules/mime/mime.js
Copy to:    <projectDir>/dist/out/mac/Electron.app/Contents/Resources/app/node_modules/mime/mime.js
Copy from:  <projectDir>/node_modules/send/node_modules/mime/types.json
Copy to:    <projectDir>/dist/out/mac/Electron.app/Contents/Resources/app/node_modules/mime/types.json
Copy from:  <projectDir>/node_modules/send/node_modules/mime/src/build.js
Copy to:    <projectDir>/dist/out/mac/Electron.app/Contents/Resources/app/node_modules/mime/src/build.js
Copy from:  <projectDir>/node_modules/send/node_modules/mime/src/test.js
Copy to:    <projectDir>/dist/out/mac/Electron.app/Contents/Resources/app/node_modules/mime/src/test.js
Copy from:  <projectDir>/node_modules/send/node_modules/mime/package.json
Copy to:    <projectDir>/dist/out/mac/Electron.app/Contents/Resources/app/node_modules/mime/package.json

Instead the node_modules folder structure should be kept as is when copying the files, such that both versions remain in the build which is necessary in this case.

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

Successfully merging a pull request may close this issue.

2 participants