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] Rollup failed to resolve import "$env/static/public" #18465

Closed
vhscom opened this issue Oct 31, 2022 · 2 comments
Closed

[BUG] Rollup failed to resolve import "$env/static/public" #18465

vhscom opened this issue Oct 31, 2022 · 2 comments

Comments

@vhscom
Copy link

vhscom commented Oct 31, 2022

Context:

  • Playwright Version: "@playwright/experimental-ct-svelte": "^1.27.1"
  • Operating System: macOS
  • Node.js version: 18.6.0
  • Browser: Chromium
  • Extra:
## System:
 - OS: macOS 12.6
 - Memory: 81.05 MB / 16.00 GB
## Binaries:
 - Node: 18.6.0 - ~/Library/Caches/fnm_multishells/77742_1666972699539/bin/node
 - Yarn: 1.22.19 - /opt/homebrew/bin/yarn
 - npm: 8.13.2 - ~/Library/Caches/fnm_multishells/77742_1666972699539/bin/npm
## Languages:
 - Bash: 5.1.16 - /opt/homebrew/bin/bash

Reduced Test Case
https://github.com/vhscom/playwright-ct-env-reduced-test

Important bits from reduced test case called out below:

tests/component/test.ts

import { test, expect } from '@playwright/experimental-ct-svelte';
import Foo from '$lib/Foo.svelte';

test('should work', async ({ mount }) => {
  const component = await mount(Foo);
  await expect(component).toContainText('Vite + Svelte');
});

src/variable.ts

import { VITE_APP_NAME } from '$env/static/public';

// the old way still works
// const variables = {
//   appName: import.meta.env.VITE_APP_NAME
// };

// the new way does not work
const variables = {
  appName: VITE_APP_NAME
};

export default variables;

Describe the bug

Above fails in supplied reduced test case, which is the Svelte boilerplate generated today with a single Environment variable added by following SvelteKit. Open src/variable.ts to the difference in the failing scenario and a working scenario. Use of functionality is security-related in SvelteKit and, as such, should enjoy first-class support in Playwright.

More background

This is likely related to sveltejs/kit#1485

@aslushnikov
Copy link
Collaborator

@vhscom we're happy to look at it when SveteKit stabilizes! So far it has been changing under our feet with every update.

Let me close this for now; feel free to re-file once SvelteKit is stable!

@vhscom
Copy link
Author

vhscom commented Nov 15, 2022

There's a workaround for this problem and that's to add a .env.production (used during build time) and drop in some empty env variables. This prevents playwright ct from failing to build using the new $env module in SK. More info in Kit docs here: https://kit.svelte.dev/docs/modules#$env-static-public.

Credit for workaround to KitQL creator @jycouet here: https://discord.com/channels/457912077277855764/1038464750578839552/1041682750278746183

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants