Skip to content

Error on loading material components #32

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

Closed
rishikeshjadhav opened this issue Jan 12, 2022 · 46 comments
Closed

Error on loading material components #32

rishikeshjadhav opened this issue Jan 12, 2022 · 46 comments

Comments

@rishikeshjadhav
Copy link

Getting below error when material components () are added,

image

@rishikeshjadhav
Copy link
Author

Adding more details as below,
bvm version: 0.0.30
bit version: 0.0.603
Angular version: [email protected]

Below are the workspace .jsonc contents:

{
"$schema": "https://static.bit.dev/teambit/schemas/schema.json",
"teambit.workspace/workspace": {
"name": "bit-cd2-ang",
"icon": "https://static.bit.dev/bit-logo.svg",
"defaultDirectory": "{scope}/{name}",
"defaultScope": "rishijadhav2792.rjcomponents"
},
"teambit.dependencies/dependency-resolver": {
"packageManager": "teambit.dependencies/pnpm",
"policy": {
"dependencies": {
"@angular/material": "13.1.1",
"@angular/forms": "13.1.1",
"@angular/cdk": "13.1.1",
"@angular/animations": "13.1.1"
},
"peerDependencies": {}
}
},
"teambit.workspace/variants": {
"*": {
"teambit.angular/[email protected]": {}
}
},
"teambit.angular/[email protected]": {},
"teambit.generator/generator": {
"aspects": [
"teambit.angular/[email protected]"
]
}
}

@rishikeshjadhav
Copy link
Author

@ocombe @debs-obrien

Looks like a similar issue as below,
#31

@ocombe
Copy link
Contributor

ocombe commented Jan 12, 2022

Hmm I wonder if the Material module needs to be pre-compiled with ngcc even in v13, I'll do some tests tomorrow

@ocombe
Copy link
Contributor

ocombe commented Jan 12, 2022

Can you try to add @angular/material to the peerDependencies in workspace.jsonc, then remove the capsule (bit capsule delete --all) and run bit install again

@rishikeshjadhav
Copy link
Author

Moved @angular/material to the peerDependencies.
Ran "bit capsule delete --all"
Ran "bit install"

Started to get below errors on bit install

image

Below is the updated workspace .jsonc contents:

{
"$schema": "https://static.bit.dev/teambit/schemas/schema.json",
"teambit.workspace/workspace": {
/**
* the name of the component workspace. used for development purposes.
/
"name": "bit-cd2-ang",
/

* set the icon to be shown on the Bit server.
/
"icon": "https://static.bit.dev/bit-logo.svg",
/

* default directory to place a component during bit import and bit create.
* the following placeholders are available:
* name - component name includes namespace, e.g. 'ui/button'.
* scopeId - full scope-id includes the owner, e.g. 'teambit.compilation'.
* scope - scope name only, e.g. 'compilation'.
* owner - owner name in bit.dev, e.g. 'teambit'.
/
"defaultDirectory": "{scope}/{name}",
/

* default scope for all components in workspace.
**/
"defaultScope": "rishijadhav2792.rjcomponents"
},
"teambit.dependencies/dependency-resolver": {
"packageManager": "teambit.dependencies/pnpm",
"policy": {
"dependencies": {
"@angular/forms": "13.1.1",
"@angular/cdk": "13.1.1",
"@angular/animations": "13.1.1"
},
"peerDependencies": {
"@angular/material": "13.1.1"
}
}
},
"teambit.workspace/variants": {
"*": {
"teambit.angular/[email protected]": {}
}
},
"teambit.angular/[email protected]": {},
"teambit.generator/generator": {
"aspects": [
"teambit.angular/[email protected]"
]
}

@rishikeshjadhav
Copy link
Author

Completed above suggested steps,

Moved @angular/material to the peerDependencies.
Ran "bit capsule delete --all"
Ran "bit install"
Ran "bit start"

Still getting same error

@rishikeshjadhav
Copy link
Author

UPDATE:

Tried with basic button component from material as well, getting similar error,

image

@rishikeshjadhav
Copy link
Author

@ocombe Let me know if you find something around this, Thanks.

@rishikeshjadhav
Copy link
Author

rishikeshjadhav commented Jan 14, 2022

UPDATE

bvm version: 0.0.30
bit version: 0.0.603
Angular: teambit.angular/[email protected]
Angular CLI: 13.1.2


  1. Created new angular project - "ng new bit-ng-thirteen"

Below is the dependency list

image

  1. Added material - "ng add @angular/material"

Below is the dependency list

image

  1. Delete node_modules folder

  2. Updated version to be consistent with material (13.1.2)

Below is the dependency list

image

  1. Ran "npm install"

  2. Added a basic material button component and verified that everyting is working fine

image

  1. Initialzed a bit repository - "bit init" - This created .bitmap file and workspace.jsonc file

  2. Updated workspace.jsonc to include angular variant

    "teambit.workspace/variants": {
    "*": {
    "teambit.angular/[email protected]": {}
    }
    },
    "teambit.angular/[email protected]": {},
    "teambit.generator/generator": {
    "aspects": [
    "teambit.angular/[email protected]"
    ]
    }

  3. Ran "bit install"

  4. Created a bit component - "bit create ng-module app/first-cmp"

  5. Added a basic material button component in newly added first-cmp

  6. Ran "ng serve" to run the Angular solution locally

  7. Got the same error as below

image

  1. Updated angular.json file to include preserveSymlinks flag set to true

    "projects.$name.architect.build.options.preserveSymlinks: true"
    
  2. Ran "ng serve" to run the Angular solution locally, This time it worked correctly

image

  1. Ran "bit compile"

  2. Ran "bit link"

  3. Ran "bit start"

It gave the same error before setting preserveSymlinks: true in angular.json file

image

@ocombe Hope this analysis will helps!

@rishikeshjadhav
Copy link
Author

rishikeshjadhav commented Jan 16, 2022

UPDATE

Tried from sratch on brand new dev boxes with below configurations,

OS: Windows 10
Node version: 12.22.7
Angular CLI version: 11.2.13
BVM version: 0.0.34
Bit version: 0.0.621

Followed below steps:

OK - bit new ng-workspace checkone -a teambit.angular/angular-v11
OK - bit create ng-module ui/my-button
OK - bit install
OK - bit start

Everything ran correctly and the component was loaded with default text.

Added material as peer dependencies using below commands,

OK - bit install @angular/[email protected] --type peer
OK - bit install @angular/[email protected] --type peer
OK - bit install @angular/[email protected] --type peer
OK - bit install @angular/[email protected] --type peer

Added new material button in above component (https://material.angular.io/components/button/examples)

  1. Imported button module in file my-button.module.ts

    import { MatButtonModule } from '@angular/material/button';

  2. Updated imports array in file my-button.module.ts

    imports: [
    MatButtonModule
    ]

  3. Added basic button component HTML in file my-button.component.ts

	<button mat-raised-button>Basic</button>
    <button mat-raised-button color="primary">Primary</button>
    <button mat-raised-button color="accent">Accent</button>
    <button mat-raised-button color="warn">Warn</button>
    <button mat-raised-button disabled>Disabled</button>

FAILED - bit start - Failed with multiple errors

Re-tried with below commands,

OK - bit capsule delete --all
OK - Delete node_modules folder

OK - bit install

FAILED - bit start - see below for error messages,


tried above steps on two different dev boxes,

Error on DEV BOX 1:

image

Error on DEV BOX 2:

image

@rishikeshjadhav
Copy link
Author

@ocombe @debs-obrien

Would be great to hear and have some help around this, kind of have hit a dead end here!

@ocombe
Copy link
Contributor

ocombe commented Jan 17, 2022

I'm working on a fix, it should be released today hopefully

@rishikeshjadhav
Copy link
Author

That's great @ocombe , Looking forward for the same, Thanks!

I will try out with adding different material components once the fix is available.

@ocombe ocombe closed this as completed in 5966591 Jan 17, 2022
@ocombe
Copy link
Contributor

ocombe commented Jan 17, 2022

Can you run the new version that I just released ?

@rishikeshjadhav
Copy link
Author

Sure, will try with teambit.angular/[email protected]

Shall I follow the same steps that i tried above on 2 DEV boxes?

Let me know if anything additional step is required.

@ocombe
Copy link
Contributor

ocombe commented Jan 17, 2022

just change the number in workspace.jsonc and run bit install, it should be enough

@rishikeshjadhav
Copy link
Author

sure, let me give it a try

@rishikeshjadhav
Copy link
Author

I tested with below material components,

Button - SUCCESS
https://material.angular.io/components/button/overview

Badge - SUCCESS
https://material.angular.io/components/badge/overview

Autocomplete - FAILED
https://material.angular.io/components/autocomplete/overview

Error -

image

Datepicker - FAILED
https://material.angular.io/components/datepicker/overview

Error -

image

Note - All imports and providers are added correctly and are working fine with standalone Angular application.

Seems like components which requires injectors/providers are not rendering correctly.

@ocombe , any thoughts on this?

I will run few more tests over this week and will update the issue.

@rishikeshjadhav
Copy link
Author

@ocombe , here is the solution if you want to give it a try,

https://github.com/rishikeshjadhav/bit-ang-mat

@ocombe
Copy link
Contributor

ocombe commented Jan 17, 2022

Hmm, nice catch, I'll take a look at it tomorrow, but that's weird

@ocombe ocombe reopened this Jan 17, 2022
@rishikeshjadhav
Copy link
Author

One observation regarding styling for material components,

When we add material support to any standalone Angular application using below command,

ng add @angular/material

It performs certain steps to add prebuilt themes, typography, etc. Refer to below URL

https://material.angular.io/guide/getting-started

How do we configure those steps while adding components using bit?

By default the material stylings are not applied

@ocombe ocombe closed this as completed in 26be553 Jan 18, 2022
@ocombe
Copy link
Contributor

ocombe commented Jan 18, 2022

I fixed the issue but I can't publish a new version right now due to a bug in bit, I'll let you know when it's available

@rishikeshjadhav
Copy link
Author

Sounds Good @ocombe , Looking forward for the new build to try out with complex material components, Thanks!

Also do check out on above observation regarding styling/effects for material components not getting applied by default.

@ocombe
Copy link
Contributor

ocombe commented Jan 18, 2022

Ah yes, you can use a custom env and do something like that (obviously adapted to material):

      angular.overrideAngularOptions({styles: [        
        require.resolve('bootstrap/dist/css/bootstrap.min.css'),
        require.resolve('@fortawesome/fontawesome-free/css/all.css'),
        require.resolve('primeicons/primeicons.css'),
        require.resolve('primeng/resources/primeng.css'),
        require.resolve('primeng/resources/themes/nova-accent/theme.css')        
      ], scripts: [
        require.resolve('jquery/dist/jquery.min.js'),
        require.resolve('bootstrap/dist/js/bootstrap.min.js')
      ]})

To generate a custom env, use the command bit create ng-env <name of env>, and then use that in your workspace.jsonc for those components.

@rishikeshjadhav
Copy link
Author

Sure, I can give this a try.
Can you please point me to some available documentation around custom env that i can refer to?

@ocombe
Copy link
Contributor

ocombe commented Jan 18, 2022

@rishikeshjadhav
Copy link
Author

rishikeshjadhav commented Jan 18, 2022

Awesome! Let me give this a try with the basic components which are working currently. Once the new build is available i will give the complex components a try as well.

Thanks @ocombe for details around this and looking forward for more exciting Angular integrations. Cheers!

@ocombe
Copy link
Contributor

ocombe commented Jan 18, 2022

I have published a new version with the fix

@rishikeshjadhav
Copy link
Author

rishikeshjadhav commented Jan 18, 2022

@ocombe

Just wanted to confirm, should i try with teambit.angular/[email protected] or teambit.angular/[email protected]

teambit.angular/[email protected] - This was the build version for your last fix.

@ocombe
Copy link
Contributor

ocombe commented Jan 18, 2022

0.0.9

@rishikeshjadhav
Copy link
Author

Sure, since the .bitmap still shows 0.0.8 for angular-v13

https://github.com/teambit/bit-angular/blob/master/.bitmap

image

@ocombe
Copy link
Contributor

ocombe commented Jan 18, 2022

updated 🙂

@rishikeshjadhav
Copy link
Author

Tested with Autocomplete component of material - FAILED

https://material.angular.io/components/autocomplete/overview


OS: Windows 10
Node version: 14.18.1
Angular CLI version: 13.1.3
BVM version: 0.0.34
Bit version: 0.0.623

Getting below error on bit start,

image

When we try to add BrowserAnimationsModule or NoopAnimationsModule in imports array of my-button.module.ts file getting below error,

image


Here is the repo to try it out,

https://github.com/rishikeshjadhav/bit-ang-autocomplete


After few google searches they are saying BrowserModule and BrowserAnimationsModule both needs to be part of root module app.module.ts and cannot be included in child modules

@ocombe, how can we ensure BrowserModule and BrowserAnimationsModule are included in root app.module.ts in our case?

@ocombe
Copy link
Contributor

ocombe commented Jan 20, 2022

Hmm BrowserModule is indeed included by default... so yeah that will be an issue for BrowserAnimationsModule, and I don't see a workaround right now. It should be fixed by the next Architecture that I'm working on (with Angular elements) though

@rishikeshjadhav
Copy link
Author

ohh okay.. any possible timeline that we are looking at currently for this fix to be available if that can be shared? 👀

Just wanted to plan and prioritize things here accordingly 😊 as currently these material components wont work.

@ocombe
Copy link
Contributor

ocombe commented Jan 20, 2022

I hope to release this change in the next 2 weeks if I don't hit any roadblock

@rishikeshjadhav
Copy link
Author

rishikeshjadhav commented Jan 20, 2022

ok great, Thanks for sharing 🙌

oh and you said BrowserModule is indeed included by default...

Similarly if we include BrowserAnimationsModule and CommonModule also by default, i believe this issue should get fixed.

Thoughts? 🤞

@rishikeshjadhav
Copy link
Author

rishikeshjadhav commented Jan 20, 2022

May be as below (Just giving it a try)

In below file,

https://github.com/teambit/bit-angular/blob/a65dc6f9732a3f22be62571e7b499cbafb8a0a7f/packages/angular/preview/src/app/app.module.ts

Update

imports: [BrowserModule, DocsModule],

TO

imports: [BrowserModule, BrowserAnimationsModule, CommonModule, DocsModule],

and adding below 2 import statements on top,

import { CommonModule } from '@angular/common';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';

@rishikeshjadhav
Copy link
Author

@ocombe , any thoughts on above possible solution? Is it feasible?

@rishikeshjadhav
Copy link
Author

@ocombe , just checking on release of next Architecture changes for Angular elements which will fix above issue?

Also, let me know if you got a chance to check on above mentioned possible solution?

ocombe added a commit that referenced this issue Jan 31, 2022
@ocombe
Copy link
Contributor

ocombe commented Jan 31, 2022

I will release a new version with the BrowserAnimationsModule instead of BrowserModule . No need to import CommonModule since it's already exported by these 2 browser modules
As for the Angular elements change, it's been delayed due to a change in the priority of the features... hopefully not by much

@rishikeshjadhav
Copy link
Author

Sounds good, let me know once the new version is available and i will give it a try. Thanks!

Do mention the version number to try with.

@ocombe
Copy link
Contributor

ocombe commented Jan 31, 2022

teambit/[email protected] has been released with the change.
But be aware of a bug in angular itself right now that will prevent you from compiling / building your files until this is fixed angular/angular-cli#22606 (maybe tomorrow?). You should still be able to run bit start. This will only appear if you delete your node modules and run bit install again (or if you create a new workspace).

@rishikeshjadhav
Copy link
Author

sure, i will give this a try tomorrow morning and update. Thanks for the release!

@rishikeshjadhav
Copy link
Author

rishikeshjadhav commented Feb 1, 2022

This is working fine with teambit.angular/[email protected].

However the default material stylings are not getting applied which are breaking the components.

I will try out the solution that you suggested by creating a custom environment using bit create ng-env <name of env>

Will create separate issue in case of any errors in that process.

@ocombe , Thank you for all the help!

@rishikeshjadhav
Copy link
Author

@ocombe , can you please check below issue which is occurring while creating custom environment,

#35

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

No branches or pull requests

2 participants