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

[macOS] Module not found: typescript-webpack can 'start' with the 'trash' package, but not 'make' #1520

Closed
3 tasks done
nathanvogel opened this issue Feb 27, 2020 · 3 comments
Labels
bug plugin/webpack Issues or pull requests related to first-party webpack plugins/templates

Comments

@nathanvogel
Copy link

nathanvogel commented Feb 27, 2020

Preflight Checklist

  • I have read the contribution documentation for this project.
  • I agree to follow the code of conduct that this project follows, as appropriate.
  • I have searched the issue tracker for a bug that matches the one I want to file, without success.

I'm not sure whether this is a problem with ElectronForge or Webpack or @stroncium/procfs, but since start works and make fails, I'm posting this as an ElectronForge issue.

Issue Details

  • Electron Forge Version:
    • 6.0.0-beta.50
  • Electron Version:
    • v8.0.2
  • Operating System:
    • macOS 10.15.3 & Linux Ubuntu 18.04 LTS

Expected Behavior

The typescript-webpack template make command can successfully build the trash package (or rather its dependency @stroncium/procfs) on macOS and Linux.

Actual Behavior

It works fine:

  • on Windows (instead of Linux/macOS)
  • or when using the default ElectronForge template (instead of typescript-webpack)
  • or when using start (instead of make)

But otherwise, I get this error:

> test-trash-webpack@1.0.0 make /Users/nathan/dev/test-trash-webpack
> electron-forge make

✔ Checking your system
✔ Resolving Forge Config
We need to package your application before we can make it
✖ Compiling Main Process Code

An unhandled error has occurred inside Forge:
Compilation errors in the main process: Hash: 76c19426585ec5cb1d9f
Version: webpack 4.41.6
Time: 3954ms
Built at: 27/02/2020 14:21:04
                           Asset      Size  Chunks         Chunk Names
                        index.js   115 KiB       0         main
                    index.js.map   459 KiB       0  [dev]  main
      native_modules/macos-trash  9.11 KiB                 
native_modules/windows-trash.exe    28 KiB                 
Entrypoint main = index.js index.js.map
 [0] external "path" 42 bytes {0} [built]
 [1] external "fs" 42 bytes {0} [built]
 [2] external "util" 42 bytes {0} [built]
 [5] external "child_process" 42 bytes {0} [built]
[11] external "electron" 42 bytes {0} [built]
[25] ./src/index.ts 1.75 KiB {0} [built]
[26] ./node_modules/trash/index.js 1.21 KiB {0} [built]
[27] ./node_modules/globby/index.js 3.17 KiB {0} [built]
[43] ./node_modules/p-try/index.js 211 bytes {0} [built]
[44] ./node_modules/is-path-inside/index.js 439 bytes {0} [built]
[45] ./node_modules/trash/lib/macos.js 738 bytes {0} [built]
[46] ./node_modules/trash/lib/linux.js 2.2 KiB {0} [built]
[94] ./node_modules/trash/lib/windows.js 563 bytes {0} [built]
[95] ./node_modules/electron-squirrel-startup/index.js 1 KiB {0} [built]
[96] ./node_modules/debug/src/index.js 314 bytes {0} [built]
    + 88 hidden modules

ERROR in ./node_modules/@stroncium/procfs/lib/parsers.js
Module not found: Error: Can't resolve './parsers/' in '/Users/nathan/dev/test-trash-webpack/node_modules/@stroncium/procfs/lib'
 @ ./node_modules/@stroncium/procfs/lib/parsers.js 48:15-42
 @ ./node_modules/@stroncium/procfs/index.js
 @ ./node_modules/trash/lib/linux.js
 @ ./node_modules/trash/index.js
 @ ./src/index.ts
Error: Compilation errors in the main process: Hash: 76c19426585ec5cb1d9f
Version: webpack 4.41.6
Time: 3954ms
Built at: 27/02/2020 14:21:04
                           Asset      Size  Chunks         Chunk Names
                        index.js   115 KiB       0         main
                    index.js.map   459 KiB       0  [dev]  main
      native_modules/macos-trash  9.11 KiB                 
native_modules/windows-trash.exe    28 KiB                 
Entrypoint main = index.js index.js.map
 [0] external "path" 42 bytes {0} [built]
 [1] external "fs" 42 bytes {0} [built]
 [2] external "util" 42 bytes {0} [built]
 [5] external "child_process" 42 bytes {0} [built]
[11] external "electron" 42 bytes {0} [built]
[25] ./src/index.ts 1.75 KiB {0} [built]
[26] ./node_modules/trash/index.js 1.21 KiB {0} [built]
[27] ./node_modules/globby/index.js 3.17 KiB {0} [built]
[43] ./node_modules/p-try/index.js 211 bytes {0} [built]
[44] ./node_modules/is-path-inside/index.js 439 bytes {0} [built]
[45] ./node_modules/trash/lib/macos.js 738 bytes {0} [built]
[46] ./node_modules/trash/lib/linux.js 2.2 KiB {0} [built]
[94] ./node_modules/trash/lib/windows.js 563 bytes {0} [built]
[95] ./node_modules/electron-squirrel-startup/index.js 1 KiB {0} [built]
[96] ./node_modules/debug/src/index.js 314 bytes {0} [built]
    + 88 hidden modules

ERROR in ./node_modules/@stroncium/procfs/lib/parsers.js
Module not found: Error: Can't resolve './parsers/' in '/Users/nathan/dev/test-trash-webpack/node_modules/@stroncium/procfs/lib'
 @ ./node_modules/@stroncium/procfs/lib/parsers.js 48:15-42
 @ ./node_modules/@stroncium/procfs/index.js
 @ ./node_modules/trash/lib/linux.js
 @ ./node_modules/trash/index.js
 @ ./src/index.ts
    at cb (/Users/nathan/dev/test-trash-webpack/node_modules/@electron-forge/plugin-webpack/src/WebpackPlugin.ts:250:31)
    at finalCallback (/Users/nathan/dev/test-trash-webpack/node_modules/webpack/lib/Compiler.js:257:39)
    at /Users/nathan/dev/test-trash-webpack/node_modules/webpack/lib/Compiler.js:273:13
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/nathan/dev/test-trash-webpack/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:4:1)
    at AsyncSeriesHook.lazyCompileHook (/Users/nathan/dev/test-trash-webpack/node_modules/tapable/lib/Hook.js:154:20)
    at onCompiled (/Users/nathan/dev/test-trash-webpack/node_modules/webpack/lib/Compiler.js:271:21)
    at /Users/nathan/dev/test-trash-webpack/node_modules/webpack/lib/Compiler.js:681:15
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/nathan/dev/test-trash-webpack/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:4:1)
    at AsyncSeriesHook.lazyCompileHook (/Users/nathan/dev/test-trash-webpack/node_modules/tapable/lib/Hook.js:154:20)
    at /Users/nathan/dev/test-trash-webpack/node_modules/webpack/lib/Compiler.js:678:31
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/nathan/dev/test-trash-webpack/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:4:1)
    at AsyncSeriesHook.lazyCompileHook (/Users/nathan/dev/test-trash-webpack/node_modules/tapable/lib/Hook.js:154:20)
    at /Users/nathan/dev/test-trash-webpack/node_modules/webpack/lib/Compilation.js:1423:35
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/nathan/dev/test-trash-webpack/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:4:1)
    at AsyncSeriesHook.lazyCompileHook (/Users/nathan/dev/test-trash-webpack/node_modules/tapable/lib/Hook.js:154:20)
    at /Users/nathan/dev/test-trash-webpack/node_modules/webpack/lib/Compilation.js:1414:32

To Reproduce

yarn create electron-app test-trash-webpack --template=typescript-webpack
cd test-trash-webpack
yarn add trash

then add this to index.ts

import trash from 'trash'
(() => trash)(); // Prevent tree-shaking

start runs fine, but make fails with the above error.

Additional Information

The same thing happens when requesting the procfs package directly:

import {procfs} from '@stroncium/procfs'
(() => procfs)(); // Prevent tree-shaking

This is the offending file: https://github.com/stroncium/nodejs-procfs/blob/master/lib/parsers.js

@Mac-Genius
Copy link

Hey @nathanvogel I've also come across this issue, but on Windows.

  • Electron Forge Version:
    • 6.0.0-beta.50
  • Electron Version:
    • 8.1.0
  • Operating System:
    • Windows 10 17763.1039 and 18362.657

I currently have a workaround that may work for you. Install string-replace-loader and in your webpack.rules.js add the following rule:

{
  test: /parsers\.js$/,
  loader: 'string-replace-loader',
  options: {
    search: 'module.exports = parsers;',
    replace: 'export default parsers;',
  }
}

Hope this helps!

@nathanvogel
Copy link
Author

Thanks @Mac-Genius, it's a bit heavy-handed, but it helped. Afterwards, I still had a few issues:

macOS
I got an EACCESS error when running the trash module afterwards, which I fixed with this:

  hooks: {
    packageAfterCopy: async (config, buildPath, version, platform) => {
      console.log("Platform::::: " + platform);
      if (platform !== "darwin") return;
      // buildPath is something like:
      // /var/folders/mv/vd2n2svd0570b614s31g5h440000gn/T/electron-packager/darwin-x64/MyApp-darwin-x64/Electron.app/Contents/Resources/app
      const trashPath = path.resolve(
        buildPath,
        ".webpack/main/native_modules/macos-trash",
      );
      await fs.chmod(trashPath, 0o755);
      console.log("Applied chmod fix for 'trash' module on macOS.");
    },
  },

Linux
I'm having this error, which I haven't looked into yet:

ProcfsError: Unknown error: parsers[name] is not a function

So there's more to it than that...

@malept malept added the plugin/webpack Issues or pull requests related to first-party webpack plugins/templates label Sep 30, 2020
@MarshallOfSound
Copy link
Member

This would be solved by using externals which is blocked by #1250

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug plugin/webpack Issues or pull requests related to first-party webpack plugins/templates
Projects
None yet
Development

No branches or pull requests

4 participants