stencil icon indicating copy to clipboard operation
stencil copied to clipboard

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

Open karthikeyan-arumugam-1558 opened this issue 1 year ago • 21 comments

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/[email protected], 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

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

christian-bromann avatar Jun 28 '24 04:06 christian-bromann

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

@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 avatar Jun 28 '24 15:06 christian-bromann

@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).

christian-bromann avatar Jun 28 '24 18:06 christian-bromann

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/*))'
  ],
  ...
}

KillerCodeMonkey avatar Jul 01 '24 11:07 KillerCodeMonkey

@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.

christian-bromann avatar Jul 01 '24 23:07 christian-bromann

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

KillerCodeMonkey avatar Jul 02 '24 05:07 KillerCodeMonkey

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

KillerCodeMonkey avatar Jul 10 '24 09:07 KillerCodeMonkey

@christian-bromann maybe not the same thing again. but maybe related? i updated the deps of a project to use ionic/angular 8.4.1 + angular 19 and in my tests i got:

SyntaxError: Cannot use import statement outside a module
node_modules/@stencil/core/internal/client/index.js:10
    import { BUILD } from "@stencil/core/internal/app-data"

I did not touched my jest config for a while. So those transformIgnorePatterns for ionic/angular/stencil are there.

Did something changed here recently?

KillerCodeMonkey avatar Dec 09 '24 15:12 KillerCodeMonkey

@KillerCodeMonkey mhm .. not sure, do you have a minimal reproduction case?

christian-bromann avatar Dec 09 '24 19:12 christian-bromann

@christian-bromann sorry i was already away from the computer yesterday evening (CEST). so here as you wish :)

https://github.com/KillerCodeMonkey/ionic8-angular19-jest-fail

KillerCodeMonkey avatar Dec 10 '24 07:12 KillerCodeMonkey

same issue in our project

JosefBredereck avatar Dec 10 '24 14:12 JosefBredereck

@KillerCodeMonkey thanks for providing the example. This indeed looks like a ESM/CJS compatibility problem that I wasn't able to resolve by tweaking the configurations. It is connected to using the @ionic/angular/standalone package. I will reopen to allow folks to investigate on this. Note that Stencil still uses CJS. Any contributions that may resolve this problem would be much appreciated.

I recommend to check out the ionic project and see how they have setup their testing infrastructure with Playwright as an alternative route.

christian-bromann avatar Dec 10 '24 18:12 christian-bromann

other testing routes are not that easy for us. We have large projects, combining node, react, electron and angular testing.

And because of the reason to avoid mixing different testing frameworks, jest was the way to go for us. So you have one test "style" through the whole project and nobody is confused when testing on frontend or backend side.

So it would be sad to transform a huge angular app to a different framework.

KillerCodeMonkey avatar Dec 11 '24 07:12 KillerCodeMonkey

We have large projects, combining node, react, electron and angular testing.

These are all things that can be tested with WebdriverIO 😉

So it would be sad to transform a huge angular app to a different framework.

There will be less work to contribute a bugfix for this problem rather than transforming the whole project to a different framework. I can unfortunately not give you an estimate when or if I am able to look into this anytime soon.

christian-bromann avatar Dec 11 '24 18:12 christian-bromann

Sure it is possible with other frameworks. So it was with jest ;-) until it Breaks ^^.

For Sure i can contribute, but for this i need time as well and need to understand why jest is not transforming this when it should like before. I used standalone Components before as well.

Am 11. Dezember 2024 19:06:07 MEZ schrieb Christian Bromann @.***>:

We have large projects, combining node, react, electron and angular testing.

These are all things that can be tested with WebdriverIO 😉

So it would be sad to transform a huge angular app to a different framework.

There will be less work to contribute a bugfix for this problem rather than transforming the whole project to a different framework. I can unfortunately not give you an estimate when or if I am able to look into this anytime soon.

-- Reply to this email directly or view it on GitHub: https://github.com/ionic-team/stencil/issues/5868#issuecomment-2536727434 You are receiving this because you were mentioned.

Message ID: @.***>

KillerCodeMonkey avatar Dec 11 '24 18:12 KillerCodeMonkey

First analysis from our side, we can update all packages, and it works fine, but as soon as we update typescript to 5.6.x the issue occurs.

Maybe this info narrows it down a bit.

JosefBredereck avatar Dec 12 '24 09:12 JosefBredereck

#5868 (comment)

Same here, when upgrading to angular 19 (we were already using standalone components) this just breaks jest, for any component using anything ionic. Guess we'll have more people running into this the upcomming days when more people find time to upgrade

Same issue occurs on typescript 5.7.x btw

Squixx avatar Dec 12 '24 13:12 Squixx

i can confirm downgrading typescript to ~5.5.x works

@christian-bromann so the chances are real, that this is more a jest-typescript es6 issue than a stencil one.

see this: https://github.com/kulshekhar/ts-jest/issues/4561

with typescript 5.6 files are transpiled to esm if the package is of type: module or the file ending is *.mts. And microsoft team states that this is the correct and intended behavior. Previously it was more like a wrong behaviour when mixing esm and cjs

KillerCodeMonkey avatar Dec 13 '24 07:12 KillerCodeMonkey

I encountered the same problem in the context of an NX monorepo (which uses Jest for testing) after migrating to version 20.2.2. The 20.2.2 NX migration includes the upgrade to Angular 19 and it sets the TypeScript version to 5.6.3 automatically. Reverting to TypeScript ~5.5.x fixed my tests.

More details (which led me here): https://stackoverflow.com/questions/79278053/nx-20-2-2-angular-19-ionic-8-jest-broken-tests-following-latest-updates

Minimal reproducible project: https://github.com/ddx001/nx-ng-ionic

ddx001 avatar Dec 14 '24 09:12 ddx001

@ddx001 I was having the exact same issue. typescript ~5.5.x indeed fixes it.

robsonos avatar Dec 19 '24 14:12 robsonos