-
Notifications
You must be signed in to change notification settings - Fork 323
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] Vite fails on 3p package that contains scss
imports during SSR pass
#869
Comments
This seems to be a mix of different issues, not entirely related to SCSS, I think. Also, there's not much we can do in Hydrogen itself. Vite, by default, won't transform files in This package provides CommonJS dist files that It also provides the source files in ESM. Therefore, there are two alternatives:
Full example of the second option: // vite.config.js
import {defineConfig} from 'vite';
import hydrogen from '@shopify/hydrogen/plugin';
import shopifyConfig from './shopify.config';
import {esbuildCommonjs, viteCommonjs} from '@originjs/vite-plugin-commonjs';
export default defineConfig({
plugins: [viteCommonjs(), hydrogen(shopifyConfig)],
ssr: {
noExternal: [/@weareallbirds\/birdponents.ui.button/],
},
optimizeDeps: {
include: ['@headlessui/react', '@weareallbirds/birdponents.ui.button'],
esbuildOptions: {
plugins: [esbuildCommonjs(['@weareallbirds/birdponents.ui.button'])],
},
},
}); For package authors, a way to simplify this would be providing an optional Hope that helps! Edit: I just noticed that option // BirdButton.client.jsx, importing from dist files
import * as Component from '@weareallbirds/birdponents.ui.button';
const Button = Component.default?.Button || Component.Button || Component;
export default function BirdButton({children}) {
return <Button>{children}</Button>;
} Perhaps this can be solved with more options around In any case, I'd recommend option // BirdButton.client.jsx, importing from source files
import {Button} from '@weareallbirds/birdponents.ui.button/button';
export default function BirdButton({children}) {
return <Button>{children}</Button>;
} |
Hey @frandiox , thanks a ton for the explanation - definitely makes sense. We'll play around with this stuff on our end, but I believe you can close this out for now as it unblocks our team. Cheers! |
Describe the bug
Vite fails to process
scss
files imported by 3p package during SSR passTo Reproduce
node_module
folder"@weareallbirds/birdponents.ui.button": "0.0.5",
intopackage.json
as a dependencysrc/routes/index.server.js
, import the client componentBy this point,
yarn dev
on the project would fail on request with just the file import.Expected behaviour
This should not fail
Additional Information
Vite does not fail if we just import
scss
file directlyThe text was updated successfully, but these errors were encountered: