-
-
Notifications
You must be signed in to change notification settings - Fork 39
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
[core] Errors thrown in non-browser environment (unsafe when referenced) #8
Comments
I wouldn't say it's a bug, rather a lack of documentation on how to export themes and In your case, you should be exposing your |
I disagree. The logic within Pigment's API is too fragile.
The issue has nothing to do with the documentation, it's about The simple solution would be to check on the existence of
|
I am not sure where the fragility comes from. Importing a file in your bundler config is different than importing the same in your source code. Imports in source code go through transforms configured in the Vite config plugins. The same is not true for imports in config files. When you are importing - import { theme } from "../pkg2/src"; Vite executes the function css() {
throw new Error(
`@pigment-css/react: You were trying to call "css" function without configuring your bundler. Make sure to install the bundler specific plugin and use it. @pigment-css/vite-plugin for Vite integration or @pigment-css/nextjs-plugin for Next.js integration.`
);
} This is because it is supposed to be compiled away during bundling and get replaced with string class name. So importing and calling the same This is the same reason that the You can try this patch in your above repo. It just removes the theme export from the main index file. commit a75173dd1270ae1497b295e5f7be9b9652805ee5
Author: Brijesh Bittu <brijeshb42@gmail.com>
Date: Mon Apr 1 13:52:37 2024 +0530
Subpath export
diff --git a/pkg1/vite.config.ts b/pkg1/vite.config.ts
index b8a532f..e48eece 100644
--- a/pkg1/vite.config.ts
+++ b/pkg1/vite.config.ts
@@ -2,7 +2,7 @@ import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import { pigment, extendTheme } from "@pigment-css/vite-plugin";
-import { theme } from "../pkg2/src";
+import { theme } from "../pkg2/src/theme";
export default defineConfig(() => ({
plugins: [
diff --git a/pkg2/src/index.ts b/pkg2/src/index.ts
index 514cada..6f6427c 100644
--- a/pkg2/src/index.ts
+++ b/pkg2/src/index.ts
@@ -1,2 +1 @@
export * as css from "./css";
-export * from "./theme"; |
I just provided you with the simplest possible example to highlight the issue. Please refer to the proposed solution in my previous reply.
|
Also, though this import is available |
@brijeshb42 in MUI X we tend to move everything that should not be imported inside an |
Yeah. I'm thinking of doing something same here.
…On Tue, 2 Apr 2024 at 6:14 PM, Flavien DELANGLE ***@***.***> wrote:
@brijeshb42 <https://github.com/brijeshb42> in MUI X we tend to move
everything that should not be imported inside an internals folder, that
way importing it feels more wrong that utils.
—
Reply to this email directly, view it on GitHub
<#8>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAFPF3VZQLKOJ2C7TAPY4ZLY3KRZLAVCNFSM6AAAAABFQW5472VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMZRHE2DKNZVGQ>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
With that being said, I do agree that we should be crystal clear about what can be imported in a config file 👍 |
Agreed. We'll have to clear these issues in our docs so that anything that goes into the config file should not be part of the code that goes into the source code. I've made a note of that. |
This issue has nothing to do with internals; and it's not a question issue.
|
Could you please describe the scenario were you have a file that contains |
The scenario is outlined in the linked repo in the first comment. The main issue is that one of the packages is exporting both It's not just about monorepo as stated. It can happen in a standalone npm package as well. |
Here's how vite treats a similar issue, TLDR as a |
Steps to reproduce
Link to live example
Steps:
npm install
(from repo's root)npm run start
(frompkg1
)theme
invite.config.ts
npm run start
(it will run without issues)Current behavior
pigment-css-vite-plugin
doesn't work when a theme is connected directly (imports a value) or imports a type from one of the files that is importing from a file with@pigment-css/react
'scss
.Expected behavior
Theme should be shareable and references shouldn't break the
pigment-css-vite-plugin
unexpectedly.Context
Btw, the bug exists in both pigment's
0.0.4
and the latest state of mui'snext
branch (checked a couple of hours ago)Your environment
npx @mui/envinfo
Search keywords: pigment vite monorepo
The text was updated successfully, but these errors were encountered: