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

bug: Import errors in angular component.ts #481

Open
3 tasks done
kartikwatwani opened this issue Sep 13, 2024 · 7 comments
Open
3 tasks done

bug: Import errors in angular component.ts #481

kartikwatwani opened this issue Sep 13, 2024 · 7 comments
Labels
package: angular @stencil/angular-output-target package type: bug Something isn't working

Comments

@kartikwatwani
Copy link

Prerequisites

Stencil Version

4.21.0

Current Behavior

I started with Stencil yesterday. Went through the documentation to integrate angular but I am unable to import the web components generated via stencil in component.ts of angular-workspace/projects/(some-more-paths)/stencil-generated/component.ts, therefore I am unable to run npm run build in angular-workspace. It was mentioned in Angular Integration documentation that we don't need to use npm link if we are using lerna monorepo but I still tried it because it was giving errors. But still no help. I tried adding paths in tsconfig.json but still no help. So, I felt maybe something with IDE so I tried it on IDX but still errors were present. I then checked with public stencil projects like revogrid and that was also configured like mine so I am not able to find what is causing this. My repo is available here.

Expected Behavior

I should be able to run npm run build in angular-workspace without import errors in stencil-generated/component.ts.

System Info

System: node 20.10.0
    Platform: darwin (24.1.0)
   CPU Model: Apple M1 (8 cpus)
    Compiler: /Users/kartikwatwani/projects/inner_growth/node_modules/@stencil/core/compiler/stencil.js
       Build: 1724698030
     Stencil: 4.21.0 🐷
  TypeScript: 5.5.3
      Rollup: 2.56.3
      Parse5: 7.1.2
      jQuery: 4.0.0-pre
      Terser: 5.31.1

Steps to Reproduce

I have reproduced in my repo.

Code Reproduction URL

https://github.com/kartikwatwani/inner-growth

Additional Information

No response

@ionitron-bot ionitron-bot bot added the triage label Sep 13, 2024
@tanner-reits tanner-reits transferred this issue from ionic-team/stencil Sep 16, 2024
@tanner-reits
Copy link
Member

@kartikwatwani Thanks for reporting! I transferred this issue to our framework output targets repo as it's an issue with our Angular output target, but did confirm something is not quite right here!

As a temporary workaround, you can apply
this patch which eliminates the build errors. In there, I also changed the customElementsExportBehavior for the dist-custom-elements output target as that needs to be set to a specific value when using the standalone option (docs here).

@tanner-reits tanner-reits added type: bug Something isn't working package: angular @stencil/angular-output-target package and removed triage labels Sep 16, 2024
@kartikwatwani
Copy link
Author

kartikwatwani commented Sep 17, 2024

Thanks, the patch worked. But will single-export-module export behavior result in whole module being loaded when I import even one component in my angular app?

@kartikwatwani
Copy link
Author

If someone wants a stencil starter with angular included by default, they can give try this repo which includes a way to rename the library name and set origin using gulp task.

@kartikwatwani
Copy link
Author

kartikwatwani commented Sep 19, 2024

I have realized 'auto-define-custom-elements' works for outputTarget:'dist-custom-elements', if we provide exports in package.json of stencil core components in the below fashion i.e. for each of the component below it is "my-component" we wish to export from the library we need to specify it in exports along with ".","loader","./standalone". Can we do something so that this exports for each component is not required in package.json?

  "exports": {
    ".": {
      "import": "./dist/index.js",
      "require": "./dist/index.cjs.js",
      "types": "./dist/types/index.d.ts"
    },
    "./standalone": {
      "import": "./dist/index.js",
      "types": "./dist/types/index.d.ts"
    },
    "./standalone/my-component.js": {
      "import": "./standalone/my-component.js",
      "types": "./standalone/my-component.d.ts"
    },
    "./loader": {
      "import": "./loader/index.js",
      "require": "./loader/index.cjs",
      "types": "./loader/index.d.ts"
    }
  }, 

@balazssoltesz
Copy link

For anyone who still needs it. I don't know if it causes any other problems, but it seems to be an easy workaround if you simply change the value of "componentCorePackage" to "stencil-library/dist" (or similar, the point is to add /dist at the end). It solved my problem for now.

@michaelkrog
Copy link

michaelkrog commented Nov 22, 2024

@balazssoltesz That fixes the majority of the compile issues in my project, however the type import for Components still fails.
import type { Components } from 'stencil-library/dist/components';

Changing it to import type { Components } from 'stencil-library/dist/types'; fixes the compile issues.

@christian-bromann
Copy link
Member

@michaelkrog @balazssoltesz do you see an opportunity here to improve the Stencil docs to make this more clear?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package: angular @stencil/angular-output-target package type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants