ionic-team / stencil

A toolchain for building scalable, enterprise-ready component systems on top of TypeScript and Web Component standards. Stencil components can be distributed natively to React, Angular, Vue, and traditional web developers from a single, framework-agnostic codebase.
https://stenciljs.com
Other
12.61k stars 790 forks source link

bug: cannot find module @stencil/core/internal/client #5868

Closed karthikeyan-arumugam-1558 closed 5 months ago

karthikeyan-arumugam-1558 commented 5 months ago

Prerequisites

Stencil Version

4.19.0

Current Behavior

I consume our component library as a dist-custom-elements in my React project using Vite bundler. Until I used 4.18.3 of @stencil/core, I didn't face this error. Started seeing this from 4.19.0.

Expected Behavior

This error shouldn't be thrown

System Info

System: node 20.12.0
    Platform: darwin (23.5.0)
   CPU Model: Apple M2 (8 cpus)
    Compiler: /Users/xxx/Documents/Projects/yyy/node_modules/@stencil/core/compiler/stencil.js
       Build: 1719433468
     Stencil: 4.19.0 🏄
  TypeScript: 5.4.5
      Rollup: 2.56.3
      Parse5: 7.1.2
      jQuery: 4.0.0-pre
      Terser: 5.31.1

Steps to Reproduce

Ours is a private component library, but install any Stencil-based component library that uses @stencil/core@4.19.0, consume a component from dist-custom-elements and try to build the consuming application.

Code Reproduction URL

NA

Additional Information

FAIL  src/features/Listings/components/DownList/DownList.test.tsx
 ● Test suite failed to run

   Cannot find module '@stencil/core/internal/client' from 'node_modules/comp-lib/dist/components/ou-avatar2.js'

   Require stack:
     node_modules/comp-lib/dist/components/ou-avatar2.js
     node_modules/comp-lib/dist/components/ou-avatar.js
     node_modules/comp-lib-react/dist/src/components/stencil-generated/index.js
     node_modules/comp-lib-react/dist/src/components/index.js
     node_modules/comp-lib-react/dist/src/index.js
     src/features/Listings/components/DownList/DownList.test.tsx
christian-bromann commented 5 months ago

@karthikeyan-arumugam-1558 any chance you can provide a minimal reproducible example?

karthikeyan-arumugam-1558 commented 5 months ago

@christian-bromann, since it's a build-time error, how would you expect the example to be?

christian-bromann commented 5 months ago

@karthikeyan-arumugam-1558 can you maybe provide a setup that reproduces the build error? It seems like you are using a Jest context, it is important for us to know if you are using Jest as a testrunner or the Stencil testrunner which uses Jest under the hood.

christian-bromann commented 5 months ago

@karthikeyan-arumugam-1558 I've added a commit to #5873 which adds a require export for this path. This seems very odd to me though since the file contents are meant to be consumed within a ESM context (in the browser).

KillerCodeMonkey commented 5 months ago

sadly this error occurs in an angular + ionic project as well, when testing with jest.

those tests where failing since 4.18.2 (https://github.com/ionic-team/stencil/issues/5786).

With 4.19.1 i get the error of that issue:

Cannot find module '@stencil/core/internal/client' from '../../node_modules/@ionic/core/components/index.js'

Part of the require stack:

Require stack:
      /node_modules/@ionic/core/components/index.js
      /node_modules/@ionic/angular/fesm2022/ionic-angular-common.mjs
      /node_modules/@ionic/angular/fesm2022/ionic-angular-standalone.mjs

I changed nothing in the jest.config. So i have something similar to that in there, which was working before.

{
  ...
  transformIgnorePatterns: [
    'node_modules/(?!(@ionic/angular|@ionic/core|ionicons|@stencil/core|@angular/*))'
  ],
  ...
}
christian-bromann commented 5 months ago

@KillerCodeMonkey thanks for the feedback. It appears that these fixes which we have merged and are about to release tomorrow have to be picked up by the Ionic Framework and then released. Please keep an eye on the upcoming releases, in the meantime please pin the version for @ionic/core to the one that doesn't contain this bug. I apologies for the inconvenience.

KillerCodeMonkey commented 5 months ago

You do not have to apologize :). Thanks for caring and responding/fixing so fast.

KillerCodeMonkey commented 4 months ago

@christian-bromann btw: it is working :) Thanks!