-
Notifications
You must be signed in to change notification settings - Fork 254
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
TypeScript issue when exporting styled
from a monorepo package
#1055
Comments
I wanted to take a look at this but couldn't reproduce the error of that example. I followed the steps @lucastobrazil provided above. Here is my fork. Once I noticed the error wasn't there I added this line to check that TypeScript was working as intended. It might be something on my side so it would be great if someone else could take a look at it as well. System information
|
@andresmarpz thanks for taking a look! try doing |
ps ill add that instruction to the reproduction steps |
Yep, you were right. I could get the reproduction working and tried a few things but couldn't find a workaround. Though, I don't know if it's really a Stitches problem, since I found #42873 and #29808 in TypeScript repository and reading a little through them it seems those are very related to your issue. |
I just ran into this and resolved it by coercing npm to install |
I faced the same issue with a pnpm monorepo. It seems to be directly related to this issue microsoft/TypeScript#48212 and seems like it won't go away until it's fixed. I ended with 3 possible workarounds Option 1: Set
|
@ivanbanov thank you so much! It worked! |
@ivanbanov for option 2, did you also put this in the root |
I solved this problem installing the |
hmm tried this but still found some issues... are you able to share the repo at all? @drianoaz 🙏 |
@gregogun I only have a @Gorthog if I understood this comment correctly, TS resolves the transitive dependencies as "out of the project" and can not simply import it (I dont understand deeply to be honest). So, based on this transitive problem what I tried was to give a happy path to the compiler, so it does not get lost with such deps. Option |
thanks for the response @ivanbanov @drianoaz manage to solve the issue with @ivanbanov second solution, turns out I had a missing ts dependency in my theme package. it is working fine but I've noticed by doing this I lose the typed HTML attributes |
Thanks for that explanation! I would like to add my 2 cents: In my case I've found the problem is due to pnpm creating multiple copies of the same npm package across the monorepo. I changed all references of said package to peerDependencies except one that stayed under dependencies. Once that was done, there was only once copy of the npm package under node_modules and the error went away. |
I faced this issue in a monorepo containing the Design System using Stitches and its applications. I tried @ivanbanov workarounds, but none worked for me (still unsure why). Instead of trying a workaround or manually using type annotation on every usage of the
// stitches.shared.ts
import { createStitches } from '@stitches/react';
// Import your theme configuration here
import { themeConfig } from './path/to/your/themeConfig';
export const stitches = createStitches(themeConfig);
export const {
styled,
css,
config,
getCssText,
globalCss,
keyframes,
} = stitches; Remember that you'll have to export this file, so update the bundling library you're using to have this file as an entry.
import { stitches, styled, css, config, getCssText, globalCss, keyframes } from './stitches.shared';
export { styled, css, config, getCssText, globalCss, keyframes };
export type CSS = StitchesCSS<typeof config>;
import { StitchesCSS } from '@stitches/react';
import { stitches, styled, css, config, getCssText, globalCss, keyframes } from 'path/to/design-system-package/stitches.shared';
export { styled, css, config, getCssText, globalCss, keyframes };
export type CSS = StitchesCSS<typeof config>; This configuration file imports the shared Stitches configuration from the design system package and re-exports it for use in the application. By doing this, we ensure the design system package and the Next.js application use the same Stitches configuration, fixing the type-related issues. This alternative solution should help resolve the error without using a workaround. 🙌🏻 |
Hope this will help, following the steps above from everyone, I still wasn't able to stop the error from showing; So I started to play around with the tsconfig.json and found that setting the moduleResolution to something other then "bundler" solved my issue; {
"compilerOptions": {
"moduleResolution": "node16",
}
} |
I faced this issue in a dead simple library and it doesn't seem like any of the solutions mentioned here are helping. |
Here you are: https://github.com/OnkelTem/_stitches-inferred
import { styled } from '@stitches/react';
export const Button = styled('button', {
backgroundColor: 'gainsboro',
borderRadius: '9999px',
fontSize: '13px',
padding: '10px 15px',
'&:hover': {
backgroundColor: 'lightgray',
},
}); TS Error:
|
Opened a new report since it happens not only in a monorepo: #1160 |
It would be cool to at least update the tsconfig of this repo... |
Bug report
Describe the bug
I have a monorepo setup (see below for minimal repro) with the following structure:
system
is where we're exportingstyled
from stitches, however when using it incore
the below TypeScript error occurs.
We managed to eliminate this error by removing
declaration: true
from thetsconfig
ofcore
, however this prevented declaration files from getting created for our components which killed TS autocompletion (a big DX reason for using stitches).Prior to moving the stitches stuff to system, it was in he core directory and worked fine.
To Reproduce
https://github.com/lucastobrazil/stitches-ts-repro
Steps to reproduce the behavior, please provide code snippets or a repository:
npm install
<-- we're using 4.4.2 to stay in line with stitchescd packages/system && npm install
<-- install within this package toopackages/core/index.ts
and you will see the typescript error belowExpected behavior
We'd expect that the typings of the
styled
function are accessible and no error occurs, whilst still being able to output declaration files fromcore
Screenshots
System information
The text was updated successfully, but these errors were encountered: