bennymeg / nx-electron

Electron schematics for nrwl nx platform
Apache License 2.0
333 stars 85 forks source link

Build not working when using separate project.json file #111

Closed rnza0u closed 3 years ago

rnza0u commented 3 years ago

Description Build fails when describing project in a separate project.json file at the project's root folder, instead of the main workspace/angular.json at the workspace root.

Error is:

Cannot destructure property 'sourceRoot' of 'workspace.projects.get(...)' as it is undefined.
TypeError: Cannot destructure property 'sourceRoot' of 'workspace.projects.get(...)' as it is undefined.
    at Object.<anonymous> (E:\dev\protonfile\node_modules\nx-electron\src\utils\workspace.js:21:17)
    at Generator.next (<anonymous>)
    at fulfilled (E:\dev\protonfile\node_modules\nx-electron\src\utils\workspace.js:5:58)

To reproduce Steps to reproduce the behavior:

  1. Move the project object into a separate "project.json" file just like the nx.js documentation describe it.
  2. Run the build target using the nx-electron builder.

Expected behavior Project should build.

Context

bennymeg commented 3 years ago

Currently, I support only workspace/angular.json at the workspace root. I do no know if nx supports splitting the configuration into separate project.json file (if so, kindly provide the docs for it). Nevertheless, I do not plan to change this behavior soon, but you are more then welcome to provide a PR.

rnza0u commented 3 years ago

Here is the documentation about this type of configuration.

https://nx.dev/l/n/core-concepts/configuration#projectjson

It is very useful when having a lots of projects within an nx.js workspace. Otherwise you end up with a 100000 lines workspace.json file.

I might add a PR about this.

bennymeg commented 3 years ago

I might fixed it when I had upgraded the plugin to version 12. I now do not rely on angular devkit anymore. Would you mind test if that works for you on v12?

rnza0u commented 3 years ago

Oh yes, this is probably why.

I was looking at the stack trace provided in my first post and the "workspace" object is from the angular devkit.

Angular devkit surely does not support separate project files, only workspace/angular.json.

I will try v12 soon and will let you know if it works or not. 👍

rnza0u commented 3 years ago

What is the update procedure for version 12 ?

The update guide says to use "ng", but since you don't use angular devkit anymore, is it still the right way ?

bennymeg commented 3 years ago

You can use nx/ng to update. The plugin should support both devkits.

rnza0u commented 3 years ago

I created at test project with nx.js@12.10.0 and nx-electron@12.0.0-alpha.5.

I generated a test electron app successfully and i put the project object into a separate project.json file.

I think the problem is gone. However i get another error while building, which is not related to the project.json issue.

Here is the stack trace:

> nx run electron-app:build 

E:\dev\test-nx\test\node_modules\nx-electron\node_modules\loader-runner\lib\LoaderRunner.js:133
                if(isError) throw e;
                            ^

Error: Digest method not supported
    at new Hash (internal/crypto/hash.js:46:19)
    at Object.createHash (crypto.js:116:10)
    at module.exports (E:\dev\test-nx\test\node_modules\nx-electron\node_modules\webpack\lib\util\createHash.js:136:53)
    at NormalModule._initBuildHash (E:\dev\test-nx\test\node_modules\nx-electron\node_modules\webpack\lib\NormalModule.js:417:16)
    at E:\dev\test-nx\test\node_modules\nx-electron\node_modules\webpack\lib\NormalModule.js:452:10
    at E:\dev\test-nx\test\node_modules\nx-electron\node_modules\webpack\lib\NormalModule.js:323:13
    at E:\dev\test-nx\test\node_modules\nx-electron\node_modules\loader-runner\lib\LoaderRunner.js:367:11
    at E:\dev\test-nx\test\node_modules\nx-electron\node_modules\loader-runner\lib\LoaderRunner.js:233:18
    at context.callback (E:\dev\test-nx\test\node_modules\nx-electron\node_modules\loader-runner\lib\LoaderRunner.js:111:13)
    at Object.loader (E:\dev\test-nx\test\node_modules\nx-electron\node_modules\ts-loader\dist\index.js:18:9)
    at LOADER_EXECUTION (E:\dev\test-nx\test\node_modules\nx-electron\node_modules\loader-runner\lib\LoaderRunner.js:119:14)
    at runSyncOrAsync (E:\dev\test-nx\test\node_modules\nx-electron\node_modules\loader-runner\lib\LoaderRunner.js:120:4)
    at iterateNormalLoaders (E:\dev\test-nx\test\node_modules\nx-electron\node_modules\loader-runner\lib\LoaderRunner.js:232:2)
    at Array.<anonymous> (E:\dev\test-nx\test\node_modules\nx-electron\node_modules\loader-runner\lib\LoaderRunner.js:205:4)
    at Storage.finished (E:\dev\test-nx\test\node_modules\enhanced-resolve\lib\CachedInputFileSystem.js:55:16)
    at E:\dev\test-nx\test\node_modules\enhanced-resolve\lib\CachedInputFileSystem.js:91:9

———————————————————————————————————————————————

>  NX   ERROR  Running target "electron-app:build" failed

  Failed tasks:

  - electron-app:build

  Hint: run the command with --verbose for more details

It seems like webpack is trying to use the native Node createHash function with this algorithm: xxhash64

I don't think that this is supported natively by Node. Maybe i need to upgrade my Node version ? I'm using 14.17.4.

Any idea ?

bennymeg commented 2 years ago

This is due to the reason I tried to stick with webpack 4, but I decided to upgrade it to webpack 5 (which will solve this issue). Also, I think project.json was introduces in nx v13, so it would be supported by nx-electron@13.