[BUG] Rollup failed to resolve import "$env/static/public"
vhscom opened this issue · 2 comments
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
@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!
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