question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] Support for vite plugins and svelte preprocess

See original GitHub issue

Context:

  • Playwright Version: [what Playwright version do you use?] 1.22
  • Operating System: [e.g. Windows, Linux or Mac] Mac
  • Node.js version: [e.g. 12.22, 14.6] 18.2
  • Browser: [e.g. All, Chromium, Firefox, WebKit] Chromium
  • Extra: [any specific details about your environment] svelte-kit, vite, unocss

System:

  • OS: macOS 12.4
  • Memory: 623.73 MB / 32.00 GB

Binaries:

  • Node: 18.2.0 - ~/Library/Caches/fnm_multishells/1664_1654253939618/bin/node
  • npm: 8.9.0 - ~/Library/Caches/fnm_multishells/1664_1654253939618/bin/npm

Languages:

  • Bash: 3.2.57 - /bin/bash

Code Snippet

use: {
    /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
    trace: 'on-first-retry',

    /* Port to use for Playwright component endpoint. */
    ctPort: 3100,

    ctViteConfig: {
      resolve: {
        alias: {
          '$lib': resolve(__dirname, './src/lib'),
        }
      },
      plugins: [
        UnoCss({ extractors: [extractorSvelte] }),
      ]
    },
// Import styles, initialize component theme here.
import "@unocss/reset/tailwind.css";
import "uno.css";
export {}

Describe the bug I am testing playwright component testing with my svelte-kit setup. I also use unocss as a css library. To make it work with svelte, I need to add it as a vite plugin. I have added the plugin configuration to playwright-ct.config.ts and have imported the library to my playwright/index.ts. However, after doing that I am getting following error

Running 1 test using 1 worker

vite v2.9.9 building for production...
✓ 3 modules transformed.
[rollup-plugin-dynamic-import-variables] Unexpected token (1:0)
file: <project-root>/apps/web/src/lib/auth/Signup.svelte:1:0

SyntaxError: Unexpected token (1:0)

    at Parser.pp$4.raise (<project-root>/common/temp/node_modules/.pnpm/rollup@2.75.5/node_modules/rollup/dist/shared/rollup.js:19844:13)
    at Parser.pp$9.unexpected (<project-root>/common/temp/node_modules/.pnpm/rollup@2.75.5/node_modules/rollup/dist/shared/rollup.js:17138:8)
    at Parser.pp$5.parseExprAtom (<project-root>/common/temp/node_modules/.pnpm/rollup@2.75.5/node_modules/rollup/dist/shared/rollup.js:19219:10)
    at Parser.pp$5.parseExprSubscripts (<project-root>/common/temp/node_modules/.pnpm/rollup@2.75.5/node_modules/rollup/dist/shared/rollup.js:19011:19)
    at Parser.pp$5.parseMaybeUnary (<project-root>/common/temp/node_modules/.pnpm/rollup@2.75.5/node_modules/rollup/dist/shared/rollup.js:18977:17)
    at Parser.pp$5.parseExprOps (<project-root>/common/temp/node_modules/.pnpm/rollup@2.75.5/node_modules/rollup/dist/shared/rollup.js:18904:19)
    at Parser.pp$5.parseMaybeConditional (<project-root>/common/temp/node_modules/.pnpm/rollup@2.75.5/node_modules/rollup/dist/shared/rollup.js:18887:19)
    at Parser.pp$5.parseMaybeAssign (<project-root>/common/temp/node_modules/.pnpm/rollup@2.75.5/node_modules/rollup/dist/shared/rollup.js:18854:19)
    at Parser.pp$5.parseExpression (<project-root>/common/temp/node_modules/.pnpm/rollup@2.75.5/node_modules/rollup/dist/shared/rollup.js:18817:19)
    at Parser.pp$8.parseStatement (<project-root>/common/temp/node_modules/.pnpm/rollup@2.75.5/node_modules/rollup/dist/shared/rollup.js:17328:45)
    at Parser.pp$8.parseTopLevel (<project-root>/common/temp/node_modules/.pnpm/rollup@2.75.5/node_modules/rollup/dist/shared/rollup.js:17195:21)
    at Parser.parse (<project-root>/common/temp/node_modules/.pnpm/rollup@2.75.5/node_modules/rollup/dist/shared/rollup.js:16967:15)
    at Function.parse (<project-root>/common/temp/node_modules/.pnpm/rollup@2.75.5/node_modules/rollup/dist/shared/rollup.js:17017:35)
    at Graph.contextParse (<project-root>/common/temp/node_modules/.pnpm/rollup@2.75.5/node_modules/rollup/dist/shared/rollup.js:23121:38)
    at Object.transform (<project-root>/common/temp/node_modules/.pnpm/vite@2.9.9/node_modules/vite/dist/node/chunks/dep-59dc6e00.js:19826:27)

TypeError: Cannot read properties of undefined (reading 'httpServer')

Vite aliases works without any issue. I start getting errors only once I add vite plugins. I have also tried adding some other vite supported plugin such as rollup-plugin-visualizer. However, it also faces the same error. They all work well in my current sveltekit setup.

Add any other details about the problem here.

Likewise, I have few configuration done using svelte-preprocess. Can I configure that in my playwright-ct config?

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Uninencommented, Jun 3, 2022

I think I found the root issue which is that I need Vue plugins for my component to work and adding those is not currently possible with the current implementation of mount. Here’s a related ticket and my comment: https://github.com/microsoft/playwright/issues/14416#issuecomment-1146062955 and here is a PR that demonstrates the problem with a working and non-working component: https://github.com/Uninen/vite-ts-tailwind-starter/pull/218

Edit: I added a clearer examples with a new commit: https://github.com/Uninen/vite-ts-tailwind-starter/pull/218 If you want to test the code, just clone the PR branch, it’s very easy to install and test out.

0reactions
pavelfeldmancommented, Jun 3, 2022

@Uninen could you file a separate ticked w/ a repro I could try? This ticket was about Svelte and is already closed. Btw, this would be a non-JSX syntax example: https://github.com/microsoft/playwright/blob/main/tests/components/ct-vue-cli/src/notation-vue.spec.ts

Read more comments on GitHub >

github_iconTop Results From Across the Web

Better handling of preprocess errors · Issue #259 · sveltejs/vite ...
Describe the problem. I was getting the error message: [vite-plugin-svelte] Cannot read property 'split' of undefined file: src ...
Read more >
vite-plugin-svelte w/ Vite 2.7+ SCSS preprocess error
This template should help get you started. developing with Svelte in Vite. ## Recommended IDE Setup. [VSCode](https://code.visualstudio.com/) +.
Read more >
Storybook + Vite + Svelte + Typescript - Stack Overflow
You'll need to add svelteOptions to your .storybook/main.cjs instead of patching in svelte support in viteFinal svelteOptions: { preprocess: ...
Read more >
TypeScript support in Svelte - Learn web development
In this section we'll show you how to set up a Svelte project with TypeScript support to give it a try. Why TypeScript?...
Read more >
@storybook/builder-vite - npm
A plugin to run and build Storybooks with Vite. ... @storybook/builder-vite as part of a larger effort to improve Vite support in Storybook....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found