analogjs / analog

The fullstack meta-framework for Angular. Powered by Vite and Nitro
https://analogjs.org
MIT License
2.5k stars 240 forks source link

Error creating Analog project using Nx #486

Closed justinrassier closed 1 year ago

justinrassier commented 1 year ago

Please provide the environment you discovered this bug in.

Which area/package is the issue in?

create-analog

Description

Creating an analog project using Nx (npx create-nx-workspace --preset=@angalogjs/platform)

Please provide the exception or error you saw

Error in the console:

npx create-nx-workspace --preset=@angalogjs/platform

 >  NX   Let's create a new workspace [https://nx.dev/getting-started/intro]

✔ Repository name                       · my-analog-project
✔ Enable distributed caching to make your CI faster · Yes

 >  NX   Nx is creating your v15.8.6 workspace.

   To make sure the command works reliably in all environments, and that the preset is applied correctly,
   Nx will run "npm install" several times. Please wait.

✔ Installing dependencies with npm
✖ Creating your workspace in my-analog-project

 >  NX   Nx failed to create a workspace.

   Exit code: 1
   Log file: /var/folders/yv/5bt721155gnddj75w9tqrty80000gn/T/tmp-26179-XPa0h2ZWsizb/error.log

Log File:

 >  NX   Command failed: npm install

   Pass --verbose to see the stacktrace.

npm ERR! must provide string spec

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/justinrassier/.npm/_logs/2023-06-26T19_18_49_988Z-debug-0.log

npm log file
0 verbose cli /Users/justinrassier/.nvm/versions/node/v18.13.0/bin/node /Users/justinrassier/.nvm/versions/node/v18.13.0/bin/npm
1 info using npm@8.19.3
2 info using node@v18.13.0
3 timing npm:load:whichnode Completed in 0ms
4 timing config:load:defaults Completed in 1ms
5 timing config:load:file:/Users/justinrassier/.nvm/versions/node/v18.13.0/lib/node_modules/npm/npmrc Completed in 1ms
6 timing config:load:builtin Completed in 1ms
7 timing config:load:cli Completed in 2ms
8 timing config:load:env Completed in 0ms
9 timing config:load:file:/Users/justinrassier/dev/my-analog-project/.npmrc Completed in 0ms
10 timing config:load:project Completed in 4ms
11 timing config:load:file:/Users/justinrassier/.npmrc Completed in 6ms
12 timing config:load:user Completed in 6ms
13 timing config:load:file:/Users/justinrassier/.nvm/versions/node/v18.13.0/etc/npmrc Completed in 0ms
14 timing config:load:global Completed in 0ms
15 timing config:load:validate Completed in 1ms
16 timing config:load:credentials Completed in 1ms
17 timing config:load:setEnvs Completed in 1ms
18 timing config:load Completed in 18ms
19 timing npm:load:configload Completed in 18ms
20 timing npm:load:mkdirpcache Completed in 1ms
21 timing npm:load:mkdirplogs Completed in 0ms
22 verbose title npm install
23 verbose argv "install"
24 timing npm:load:setTitle Completed in 17ms
25 timing config:load:flatten Completed in 2ms
26 timing npm:load:display Completed in 4ms
27 verbose logfile logs-max:10 dir:/Users/justinrassier/.npm/_logs
28 verbose logfile /Users/justinrassier/.npm/_logs/2023-06-26T19_18_49_988Z-debug-0.log
29 timing npm:load:logFile Completed in 4ms
30 timing npm:load:timers Completed in 0ms
31 timing npm:load:configScope Completed in 0ms
32 timing npm:load Completed in 45ms
33 timing arborist:ctor Completed in 1ms
34 silly logfile start cleaning logs, removing 1 files
35 timing idealTree Completed in 3ms
36 timing command:install Completed in 9ms
37 verbose stack TypeError: must provide string spec
37 verbose stack     at new Edge (/Users/justinrassier/.nvm/versions/node/v18.13.0/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/edge.js:51:13)
37 verbose stack     at [_loadDepType] (/Users/justinrassier/.nvm/versions/node/v18.13.0/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/node.js:887:9)
37 verbose stack     at [Arborist.Node._loadDeps] (/Users/justinrassier/.nvm/versions/node/v18.13.0/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/node.js:864:23)
37 verbose stack     at new Node (/Users/justinrassier/.nvm/versions/node/v18.13.0/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/node.js:256:20)
37 verbose stack     at [rootNodeFromPackage] (/Users/justinrassier/.nvm/versions/node/v18.13.0/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:389:18)
38 verbose cwd /Users/justinrassier/dev/my-analog-project
39 verbose Darwin 22.5.0
40 verbose node v18.13.0
41 verbose npm  v8.19.3
42 error must provide string spec
43 verbose exit 1
44 timing npm Completed in 136ms
45 verbose unfinished npm timer reify 1687807130113
46 verbose unfinished npm timer reify:loadTrees 1687807130116
47 verbose unfinished npm timer idealTree:init 1687807130117
48 verbose code 1
49 error A complete log of this run can be found in:
49 error     /Users/justinrassier/.npm/_logs/2023-06-26T19_18_49_988Z-debug-0.log

Other information

No response

I would be willing to submit a PR to fix this issue

brandonroberts commented 1 year ago

Looks like you have an old version of create-nx-workspace by the message of it saying 15.8.6. Try

npx create-nx-workspace@latest --preset=@angalogjs/platform
justinrassier commented 1 year ago

Same thing:

 ✘  ~/dev  npx create-nx-workspace@latest --preset=@angalogjs/platform

 >  NX   Let's create a new workspace [https://nx.dev/getting-started/intro]

✔ Where would you like to create your workspace? · org
✔ Enable distributed caching to make your CI faster · No

 >  NX   Creating your v16.4.0 workspace.

   To make sure the command works reliably in all environments, and that the preset is applied correctly,
   Nx will run "npm install" several times. Please wait.

✔ Installing dependencies with npm
✖ Creating your workspace in org

 >  NX   Failed to create a workspace.

   Exit code: 1
   Log file: /var/folders/yv/5bt721155gnddj75w9tqrty80000gn/T/tmp-38609-NUnKUjI9OT96/error.log

 >  NX   Command failed: npm install

   Pass --verbose to see the stacktrace.

npm ERR! must provide string spec

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/justinrassier/.npm/_logs/2023-06-26T19_55_55_716Z-debug-0.log
0 verbose cli /Users/justinrassier/.nvm/versions/node/v18.13.0/bin/node /Users/justinrassier/.nvm/versions/node/v18.13.0/bin/npm
1 info using npm@8.19.3
2 info using node@v18.13.0
3 timing npm:load:whichnode Completed in 0ms
4 timing config:load:defaults Completed in 1ms
5 timing config:load:file:/Users/justinrassier/.nvm/versions/node/v18.13.0/lib/node_modules/npm/npmrc Completed in 2ms
6 timing config:load:builtin Completed in 2ms
7 timing config:load:cli Completed in 1ms
8 timing config:load:env Completed in 1ms
9 timing config:load:file:/Users/justinrassier/dev/org/.npmrc Completed in 1ms
10 timing config:load:project Completed in 5ms
11 timing config:load:file:/Users/justinrassier/.npmrc Completed in 0ms
12 timing config:load:user Completed in 0ms
13 timing config:load:file:/Users/justinrassier/.nvm/versions/node/v18.13.0/etc/npmrc Completed in 0ms
14 timing config:load:global Completed in 0ms
15 timing config:load:validate Completed in 1ms
16 timing config:load:credentials Completed in 1ms
17 timing config:load:setEnvs Completed in 0ms
18 timing config:load Completed in 13ms
19 timing npm:load:configload Completed in 13ms
20 timing npm:load:mkdirpcache Completed in 1ms
21 timing npm:load:mkdirplogs Completed in 0ms
22 verbose title npm install
23 verbose argv "install"
24 timing npm:load:setTitle Completed in 16ms
25 timing config:load:flatten Completed in 2ms
26 timing npm:load:display Completed in 3ms
27 verbose logfile logs-max:10 dir:/Users/justinrassier/.npm/_logs
28 verbose logfile /Users/justinrassier/.npm/_logs/2023-06-26T19_55_55_716Z-debug-0.log
29 timing npm:load:logFile Completed in 3ms
30 timing npm:load:timers Completed in 1ms
31 timing npm:load:configScope Completed in 0ms
32 timing npm:load Completed in 38ms
33 timing arborist:ctor Completed in 0ms
34 silly logfile start cleaning logs, removing 1 files
35 silly logfile done cleaning log files
36 timing idealTree Completed in 2ms
37 timing command:install Completed in 9ms
38 verbose stack TypeError: must provide string spec
38 verbose stack     at new Edge (/Users/justinrassier/.nvm/versions/node/v18.13.0/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/edge.js:51:13)
38 verbose stack     at [_loadDepType] (/Users/justinrassier/.nvm/versions/node/v18.13.0/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/node.js:887:9)
38 verbose stack     at [Arborist.Node._loadDeps] (/Users/justinrassier/.nvm/versions/node/v18.13.0/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/node.js:864:23)
38 verbose stack     at new Node (/Users/justinrassier/.nvm/versions/node/v18.13.0/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/node.js:256:20)
38 verbose stack     at [rootNodeFromPackage] (/Users/justinrassier/.nvm/versions/node/v18.13.0/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:389:18)
39 verbose cwd /Users/justinrassier/dev/org
40 verbose Darwin 22.5.0
41 verbose node v18.13.0
42 verbose npm  v8.19.3
43 error must provide string spec
44 verbose exit 1
45 timing npm Completed in 115ms
46 verbose unfinished npm timer reify 1687809355822
47 verbose unfinished npm timer reify:loadTrees 1687809355825
48 verbose unfinished npm timer idealTree:init 1687809355826
49 verbose code 1
50 error A complete log of this run can be found in:
50 error     /Users/justinrassier/.npm/_logs/2023-06-26T19_55_55_716Z-debug-0.log
brandonroberts commented 1 year ago

Will you try them as separate steps?

npx create-nx-workspace@latest analog-workspace --preset=empty
cd analog-workspace
npm i @analogjs/platform --save-dev
npx nx g @analogjs/platform:app analog-app
justinrassier commented 1 year ago

Each of those steps worked just fine independently.

What I ended up with is a Nx workspace but no package.json scripts that I can run to see if it spins up. Tried running $(npm bin)/ng serve but end up with the following error

Error: This command is not available when running the Angular CLI outside a workspace.

Here is the repo after I ran each of the commands, committed, and pushed:

https://github.com/justinrassier/analog-workspace

Let me know if you need any other info!

brandonroberts commented 1 year ago

Thanks, that helps. Does nx serve analog-app work? ng serve won't be valid in a "vanilla" Nx workspace

justinrassier commented 1 year ago

Oh duh, of course. Yes, nx serve analog-app works 🤔

JoeyHengst commented 1 year ago

Windows 11 Node 19.9.0 Npm 9.5.1

npx create-nx-workspace --preset=@analogjs/platform

NX Let's create a new workspace [https://nx.dev/getting-started/intro]

√ Where would you like to create your workspace? · test √ Enable distributed caching to make your CI faster · Yes

NX Creating your v16.4.0 workspace.

To make sure the command works reliably in all environments, and that the preset is applied correctly, Nx will run "npm install" several times. Please wait.

✔ Installing dependencies with npm ✔ Successfully created the workspace: test. √ What name would you like to use for your Analog app? · test √ Add TailwindCSS for styling? (Y/n) · true √ Add tRPC for typesafe client/server interaction? (y/N) · true Angular has not been installed yet. Creating an Angular application Fetching @nx/angular... Fetching @angular-devkit/core...

NX generateFiles: No files found in "/Users/GEBRUI~1/AppData/Local/Temp/tmp-2040-4QSFy5JJYK3e/node_modules/@nx/js/src/generators/init/files". Are you sure you specified the correct path?

Error: generateFiles: No files found in "/Users/GEBRUI~1/AppData/Local/Temp/tmp-7856-EPpD8Kkxvv3b/node_modules/@nx/js/src/generators/init/files". Are you sure you specified the correct path? at generateFiles (C:\Users\GEBRUI~1\AppData\Local\Temp\tmp-7856-EPpD8Kkxvv3b\node_modules\@nx\devkit\src\generators\generate-files.js:35:15) at C:\Users\GEBRUI~1\AppData\Local\Temp\tmp-7856-EPpD8Kkxvv3b\node_modules\@nx\js\src\generators\init\init.js:44:40 at Generator.next () at C:\Users\GEBRUI~1\AppData\Local\Temp\tmp-7856-EPpD8Kkxvv3b\node_modules\tslib\tslib.js:169:75 at new Promise () at Object.__awaiter (C:\Users\GEBRUI~1\AppData\Local\Temp\tmp-7856-EPpD8Kkxvv3b\node_modules\tslib\tslib.js:165:16) at initGenerator (C:\Users\GEBRUI~1\AppData\Local\Temp\tmp-7856-EPpD8Kkxvv3b\node_modules\@nx\js\src\generators\init\init.js:40:20) at Object. (C:\Users\GEBRUI~1\AppData\Local\Temp\tmp-7856-EPpD8Kkxvv3b\node_modules\@nx\angular\src\generators\init\init.js:36:53) at Generator.next () at C:\Users\GEBRUI~1\AppData\Local\Temp\tmp-7856-EPpD8Kkxvv3b\node_modules\tslib\tslib.js:169:75

Pass --verbose to see the stacktrace.

NX Failed to apply preset: @analogjs/platform

See above

Same issue when I do the commands seperate: PS D:\Github\analog-workspace> npx nx g @analogjs/platform:app analog-app

NX Generating @analogjs/platform:app

√ Add TailwindCSS for styling? (Y/n) · true √ Add tRPC for typesafe client/server interaction? (y/N) · true Angular has not been installed yet. Creating an Angular application Fetching @nx/angular...

NX generateFiles: No files found in "/Users/GEBRUI~1/AppData/Local/Temp/tmp-30584-8HyI26OvVCEM/node_modules/@nx/js/src/generators/init/files". Are you sure you specified the correct path?

Pass --verbose to see the stacktrace.

jeremyhofer commented 1 year ago

Wanted to mention. #481 merged yesterday, which aimed to fix and improve installation in Nx 15.X and latest 16.X workspaces. There were inconsistencies with the dependency versions installed via the plugin before, especially working in a Nx 15.x workspace which only supports Angular 15 (after Nx 15.2.0).

This change is current in main and will be available in the next Analog patch version when @brandonroberts bumps versions. It would be helpful to know if the changes from the PR helped fix any of the mentioned install issues.

justinrassier commented 1 year ago

@jeremyhofer I will make a note to give it a try!

luishcastroc commented 1 year ago

Wanted to mention. #481 merged yesterday, which aimed to fix and improve installation in Nx 15.X and latest 16.X workspaces. There were inconsistencies with the dependency versions installed via the plugin before, especially working in a Nx 15.x workspace which only supports Angular 15 (after Nx 15.2.0).

This change is current in main and will be available in the next Analog patch version when @brandonroberts bumps versions. It would be helpful to know if the changes from the PR helped fix any of the mentioned install issues.

I can add to this that I've had the same issue before.

if I use npx create-nx-workspace --preset=@analogjs/platform I get an error:

✔ Repository name                       · test
✔ Enable distributed caching to make your CI faster · Yes

 >  NX   Nx is creating your v15.0.4 workspace.

   To make sure the command works reliably in all environments, and that the preset is applied correctly,
   Nx will run "npm install" several times. Please wait.

✔ Installing dependencies with npm
✖ Creating your workspace in test

 >  NX   Nx failed to create a workspace.

   Exit code: 1
   Log file: /var/folders/t7/jrn06vw92b94w8jstyv5pyj40000gn/T/tmp-83391-Fu8tvfnmfP82/error.log

and this is the log:


>  NX  Generating @nrwl/workspace/generators.json:new

CREATE test/.editorconfig
CREATE test/.gitignore
CREATE test/.prettierignore
CREATE test/.vscode/extensions.json
CREATE test/package.json
CREATE test/tools/generators/.gitkeep
CREATE test/tools/tsconfig.tools.json
CREATE test/tsconfig.base.json
CREATE test/nx.json
CREATE test/.prettierrc
CREATE test/apps/.gitkeep
CREATE test/libs/.gitkeep

added 620 packages, and audited 621 packages in 12s

65 packages are looking for funding
  run `npm fund` for details

30 moderate severity vulnerabilities

To address issues that do not require attention, run:
  npm audit fix

To address all issues (including breaking changes), run:
  npm audit fix --force

Run `npm audit` for details.

 >  NX   Cannot convert undefined or null to object

 >  NX   Workspace creation failed, see above.

   Pass --verbose to see the stacktrace.

however if I use @latest to create the workspace:

npx create-nx-workspace@latest --preset=@analogjs/platform

 >  NX   Let's create a new workspace [https://nx.dev/getting-started/intro]

✔ Where would you like to create your workspace? · analog-project
✔ Enable distributed caching to make your CI faster · Yes

 >  NX   Creating your v16.4.2 workspace.

   To make sure the command works reliably in all environments, and that the preset is applied correctly,
   Nx will run "npm install" several times. Please wait.

✔ Installing dependencies with npm
✔ Successfully created the workspace: analog-project.
✔ What name would you like to use for your Analog app? · analog-project
✔ Add TailwindCSS for styling? (Y/n) · true
✔ Add tRPC for typesafe client/server interaction? (y/N) · false
Angular has not been installed yet. Creating an Angular application
Fetching @nx/angular...
Fetching @angular-devkit/core...
Fetching prettier...
✔ NxCloud has been set up successfully

 >  NX   Distributed caching via Nx Cloud has been enabled

   In addition to the caching, Nx Cloud provides config-free distributed execution,
   UI for viewing complex runs and GitHub integration. Learn more at https://nx.app

   Your workspace is currently unclaimed. Run details from unclaimed workspaces can be viewed on cloud.nx.app by anyone
   with the link. Claim your workspace at the following link to restrict access.

   https://cloud.nx.app/orgs/workspace-setup?accessToken=ODNiN2Y0NjgtYmE0My00NGUyLWE1OTQtNDQyZWQ0YTJmODdjfHJlYWQtd3JpdGU=

 >  NX   Successfully applied preset: @analogjs/platform

should we always consider creating a new project using Nx 16 if yes should we update the documentation to point to that? @brandonroberts

brandonroberts commented 1 year ago

@luishcastroc yes I think that should be recommended for the install command.

JoeyHengst commented 1 year ago

Getting the following error with version 16.4.2

PS D:\Github> npx create-nx-workspace@latest --preset=@angalogjs/platform --verbose

NX Let's create a new workspace [https://nx.dev/getting-started/intro]

√ Where would you like to create your workspace? · analog √ Enable distributed caching to make your CI faster · Yes

NX Creating your v16.4.2 workspace.

To make sure the command works reliably in all environments, and that the preset is applied correctly, Nx will run "npm install" several times. Please wait.

✔ Installing dependencies with npm ✖ Creating your workspace in analog

NX Failed to create a workspace.

Exit code: 1 Log file: C:\Users\GEBRUI~1\AppData\Local\Temp\tmp-2432-G7RwuK4pRdks\error.log

PS D:\Github>

error from log file:

NX Command failed: npm install

Error: Command failed: npm install at checkExecSyncError (node:child_process:885:11) at execSync (node:child_process:957:15) at installPackagesTask (C:\Users\GEBRUI~1\AppData\Local\Temp\tmp-2432-G7RwuK4pRdks\node_modules\@nx\devkit\src\tasks\install-packages-task.js:28:38) at C:\Users\GEBRUI~1\AppData\Local\Temp\tmp-2432-G7RwuK4pRdks\node_modules\@nx\workspace\src\generators\new\new.js:18:46 at Generator.next () at C:\Users\GEBRUI~1\AppData\Local\Temp\tmp-2432-G7RwuK4pRdks\node_modules\tslib\tslib.js:169:75 at new Promise () at Object.__awaiter (C:\Users\GEBRUI~1\AppData\Local\Temp\tmp-2432-G7RwuK4pRdks\node_modules\tslib\tslib.js:165:16) at C:\Users\GEBRUI~1\AppData\Local\Temp\tmp-2432-G7RwuK4pRdks\node_modules\@nx\workspace\src\generators\new\new.js:17:30

npm ERR! must provide string spec

npm ERR! A complete log of this run can be found in: npm ERR! C:\Users\Gebruiker\AppData\Local\npm-cache_logs\2023-07-03T16_39_58_180Z-debug-0.log

jeremyhofer commented 1 year ago

@justinrassier @JoeyHengst reviewing both of your stack traces, can you double check the command that's being run? It looks like there is a typo in the preset being supplied to create-nx-workspace. The preset should be @analogjs/platform. Looks like @angalogjs/platform (an extra g in there). Hopefully this helps!

I can add to this that I've had the same issue before.

if I use npx create-nx-workspace --preset=@analogjs/platform I get an error:


✔ Repository name                       · test
✔ Enable distributed caching to make your CI faster · Yes

 >  NX   Nx is creating your v15.0.4 workspace.

@luishcastroc Nx 15.0.4 is not supported. Analog requires Angular v15 as a minimum requirement. Nx did not add support for Angular v15 until Nx v15.2.0.

The latest nx-plugin that should now be available should fail if you now try to run it in a pre-15.2.0 workspace. Newer Nx versions should be supported with Angular 15.x being installed for all Nx versions between 15.2.0 and 16.0.0, along with Analog dependencies valid for Angular 15.x. For Nx versions 16.1.0 and newer latest Angular 16.x will be installed with latest Analog dependencies and versions.

should we always consider creating a new project using Nx 16 if yes should we update the documentation to point to that? @brandonroberts

I can work on updating the docs. Forgot about this after wrapping up my initial PR. I can work on the updates later today unless someone else gets to it first.

luishcastroc commented 1 year ago

@justinrassier @JoeyHengst reviewing both of your stack traces, can you double check the command that's being run? It looks like there is a typo in the preset being supplied to create-nx-workspace. The preset should be @analogjs/platform. Looks like @angalogjs/platform (an extra g in there). Hopefully this helps!

I can add to this that I've had the same issue before. if I use npx create-nx-workspace --preset=@analogjs/platform I get an error:

✔ Repository name                       · test
✔ Enable distributed caching to make your CI faster · Yes

 >  NX   Nx is creating your v15.0.4 workspace.

@luishcastroc Nx 15.0.4 is not supported. Analog requires Angular v15 as a minimum requirement. Nx did not add support for Angular v15 until Nx v15.2.0.

The latest nx-plugin that should now be available should fail if you now try to run it in a pre-15.2.0 workspace. Newer Nx versions should be supported with Angular 15.x being installed for all Nx versions between 15.2.0 and 16.0.0, along with Analog dependencies valid for Angular 15.x. For Nx versions 16.1.0 and newer latest Angular 16.x will be installed with latest Analog dependencies and versions.

should we always consider creating a new project using Nx 16 if yes should we update the documentation to point to that? @brandonroberts

I can work on updating the docs. Forgot about this after wrapping up my initial PR. I can work on the updates later today unless someone else gets to it first.

yeah I assumed my 15.0.4 might be the problem I updated the documents already and sent the PR (which is merged) thanks for clarifying .

justinrassier commented 1 year ago

ooooof I am so sorry I didn't catch that typo earlier. Yes, everything works great if you don't have a typo in the preset.

Sorry for sending you down a rabbit hole!

luishcastroc commented 1 year ago

ooooof I am so sorry I didn't catch that typo earlier. Yes, everything works great if you don't have a typo in the preset.

Sorry for sending you down a rabbit hole!

I guess false alarm and erro can be closed @brandonroberts