-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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" #18825
Comments
Hi, SvelteKit maintainer here. I think the issue is the usage of I wouldn't recommend it be implemented that way because you're going to be missing all of our Vite plugins, will be missing the user's Vite config, will need to redeclare a bunch of stuff (as can be seen in that example where |
@benmccann would you mind fleshing out how this could be achieved using the techniques Storybook use? This thread is still the canonical thread on this problem, and I've still not been able to piece together how to get this working. You commented in this storybook issue about vite config that seems related, but I could not get anything working using hints from there. Thanks! |
Any news on this? I'm blocked too with |
From Storybook's implementation, (1 of 2) and (2 of 2), I worked out the following. It successfully runs normal Svelte components, but still throws errors when trying to use an import like import { defineConfig } from '@playwright/experimental-ct-svelte'
import viteConfig from './vite.config'
import type { UserConfig, PluginOption } from 'vite'
export default defineConfig({
use: {
ctViteConfig: removeSvelteKitCompilePlugin(viteConfig),
},
})
async function removeSvelteKitCompilePlugin(config: UserConfig) {
const pluginsToRemove = [
'vite-plugin-sveltekit-compile',
'vite-plugin-sveltekit-guard', // ensures client-side code can't accidentally import server-side code (useless in this context)
]
const plugins = await withoutVitePlugins(config.plugins || [], pluginsToRemove)
return { ...config, plugins }
}
async function withoutVitePlugins(
plugins: PluginOption[],
namesToRemove: string[],
): Promise<PluginOption[]> {
const result: PluginOption[] = []
const resolvedPlugins = await Promise.all(plugins)
for (const plugin of resolvedPlugins) {
if (Array.isArray(plugin))
result.push(await withoutVitePlugins(plugin, namesToRemove))
if (plugin && 'name' in plugin && !namesToRemove.includes(plugin.name))
result.push(plugin)
}
return result
} It may have to do with an additional plugin needing awaited as discussed in histoire-dev/histoire#393 But even after modeling my function after Histoire's implementation as seen in https://github.com/histoire-dev/histoire/pull/402/files#diff-b139a32e00b9080e8307447aa2708eefe0cb582d2c22dbd612b778c4490ee9ac and written below I had no luck. async function withoutVitePlugins2(
plugins: PluginOption[],
namesToRemove: string[],
): Promise<PluginOption[]> {
let flatPlugins: PluginOption[] = []
for (const pluginOption of plugins) {
const resolvedPluginOption = await pluginOption
if (Array.isArray(resolvedPluginOption))
flatPlugins.push(...await Promise.all(resolvedPluginOption))
else
flatPlugins.push(resolvedPluginOption)
}
flatPlugins = flatPlugins.filter(Boolean)
flatPlugins = flatPlugins.filter(plugin => !namesToRemove.includes(plugin?.name))
return flatPlugins
} And for reference, the vite-plugin-sveltekit-compile plugin source code I'm going a little different direction now with my component testing, but perhaps this can be a starting point for others. |
@jacob-8 is your implementation an overall improvement from what's in Playwright now? E.g. does it fix |
Same problem here. If I replace the import path with a relative one to avoid the resolve alias altogether, it fails with an unexpected token on a // playwright-ct.config.ts
import { defineConfig } from "@playwright/experimental-ct-svelte";
import { sveltekit } from "@sveltejs/kit/vite";
export default defineConfig({
use: {
ctViteConfig: {
plugins: [sveltekit()], // this does not seem to work (`Unexpected token, expected "}"`) on a `:`)
resolve: {
alias: {
$lib: resolve('src/lib') // this doesn't work either
}
},
},
}); I'm using the Svelte 5 preview and haven't tried the same with a stable release. So maybe that's part of the problem, I don't know. |
This is a continuation of #18465. Maintainer asked to re-open when SvelteKit was stable. SvelteKit is on 1.0 track and is considered stable by its maintainers as noted in the docs Introduction and in the FAQ.
Context:
"@playwright/experimental-ct-svelte": "^1.27.1"
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
src/variable.ts
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
The text was updated successfully, but these errors were encountered: