ux icon indicating copy to clipboard operation
ux copied to clipboard

[LiveComponent] Webpack throws 272 errors when testing lib isn't installed

Open allejo opened this issue 2 years ago • 6 comments

I've included the ux-live-component library as specified in the README with having my package.json have the filepath to the vendor folder.

"@symfony/ux-live-component": "file:vendor/symfony/ux-live-component/assets",

I happen not to have Jest installed in my project and I end up getting my console spammed with a flood of errors where Webpack is trying to incorporate the testing directory for the library.

...

 error  in /home/allejo/my-project/vendor/symfony/ux-live-component/assets/test/controller/render.test.ts                                                                                                                                                                                                                   10:40:01 PM

[tsl] ERROR in /home/allejo/my-project/vendor/symfony/ux-live-component/assets/test/controller/render.test.ts(101,5)
      TS2582: Cannot find name 'it'. Do you need to install type definitions for a test runner? Try `npm i --save-dev @types/jest` or `npm i --save-dev @types/mocha`.

 error  in /home/allejo/my-project/vendor/symfony/ux-live-component/assets/test/controller/render.test.ts                                                                                                                                                                                                                   10:40:01 PM

[tsl] ERROR in /home/allejo/my-project/vendor/symfony/ux-live-component/assets/test/controller/render.test.ts(103,17)
      TS2339: Property 'element' does not exist on type 'TestData'.

 error  in /home/allejo/my-project/vendor/symfony/ux-live-component/assets/test/controller/render.test.ts                                                                                                                                                                                                                   10:40:01 PM

[tsl] ERROR in /home/allejo/my-project/vendor/symfony/ux-live-component/assets/test/controller/render.test.ts(120,9)
      TS2304: Cannot find name 'expect'.

Entrypoint app [big] 2.83 MiB (210 KiB) = runtime.js 14.6 KiB vendors-node_modules_symfony_stimulus-bridge_dist_index_js-node_modules_bootstrap_dist_js_boo-180201.css 1.08 MiB vendors-node_modules_symfony_stimulus-bridge_dist_index_js-node_modules_bootstrap_dist_js_boo-180201.js 1.46 MiB app.css 10.1 KiB app.js 274 KiB 2 auxiliary assets
webpack compiled with 272 errors

After installing jest and @types/jest in my parent project (even though I don't need it), I get some updated errors but still related to running tests.

...

 error  in /home/allejo/my-project/vendor/symfony/ux-live-component/assets/test/controller/render.test.ts                                                                                                                                                                                                                   10:57:28 PM

[tsl] ERROR in /home/allejo/my-project/vendor/symfony/ux-live-component/assets/test/controller/render.test.ts(103,17)
      TS2339: Property 'element' does not exist on type 'TestData'.

 error  in /home/allejo/my-project/vendor/symfony/ux-live-component/assets/test/controller/render.test.ts                                                                                                                                                                                                                   10:57:28 PM

[tsl] ERROR in /home/allejo/my-project/vendor/symfony/ux-live-component/assets/test/controller/render.test.ts(120,29)
      TS2339: Property 'toHaveTextContent' does not exist on type 'Matchers<void, any>'.

It'd be nice if there was some way for Webpack to ignore the test folder of this library. Installing Jest

allejo avatar Jan 21 '22 07:01 allejo

Hey!

Hmm, that's very odd - I haven't gotten this error. Is there ANYTHING special about your setup? I guess, you probably have typescript installed and enabled on Encore? Is that correct? Anything else custom?

Cheers!

weaverryan avatar Jan 24 '22 20:01 weaverryan

Hello,

I experienced a similar issue and it was due to Typescript being ran on the vendor files (because the module in node_modules is actually a symbolic link).

You should be able to fix this problem by adding the following configuration in your tsconfig.json file:

{
    "exclude": [
        "node_modules",
        "vendor"
    ]
}

tgalopin avatar Jan 25 '22 15:01 tgalopin

I can confirm that adding the exclude to my tsconfig.json file solved the problem! Maybe this could be documented or included as a magical check/patch during install?

allejo avatar Jan 28 '22 17:01 allejo

Thank you for this issue. There has not been a lot of activity here for a while. Has this been resolved?

carsonbot avatar Apr 26 '24 12:04 carsonbot

Friendly ping? Should this still be open? I will close if I don't hear anything.

carsonbot avatar May 11 '24 08:05 carsonbot

Hey,

I didn't hear anything so I'm going to close it. Feel free to comment if this is still relevant, I can always reopen!

carsonbot avatar May 25 '24 14:05 carsonbot