-
-
Notifications
You must be signed in to change notification settings - Fork 124
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
fail to resolve packages imported from another package in a monorepo #429
Comments
So, is this an issue that happens only with monorepo? |
What package manager are you using? and what's your vite config |
@himself65 I'm using import path from "node:path"
import url from "node:url"
import { defineConfig } from "vite"
import { stylexPlugin } from "vite-plugin-stylex-dev"
import tsconfigPaths from "vite-tsconfig-paths"
const workspacesRoot = path.resolve(
path.dirname(url.fileURLToPath(import.meta.url)),
"..",
)
export default defineConfig(({ mode }) => {
return {
plugins: [
tsconfigPaths({
projects: [
"./tsconfig.json",
"../browser-api/tsconfig.json",
"../browser-lib/tsconfig.json",
"../browser-ui/tsconfig.json",
],
}),
stylexPlugin({
unstable_moduleResolution: {
type: "commonJS",
rootDir: workspacesRoot,
},
}),
],
}
}) |
what is |
it is for to configure for looking styles of stylex from the root of monorepo but I think that it is maybe unnecessary. Anyway, I did test removing that but unfortunately the error persists. |
Is there any code for reproduction? I'm guessing there is some issue with vite |
While I was preparing a repo for you to try, I already know what causes it. {
"extends": "../tsconfig.json",
"compilerOptions": {
"alwaysStrict": true,
"preserveConstEnums": true,
"strictNullChecks": true,
"strict": true,
"sourceMap": true,
"paths": {
"@/*": ["./*"]
},
"module": "esnext",
"moduleResolution": "Bundler",
"target": "esnext",
"baseUrl": ".", // <--- problem here!!
"jsx": "react-jsx",
"lib": ["DOM", "DOM.Iterable", "ESNext"],
"allowJs": false,
"experimentalDecorators": true,
"esModuleInterop": false,
"resolveJsonModule": true,
"isolatedModules": true,
"skipLibCheck": false,
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true
},
"include": ["**/*.ts", "**/*.tsx"]
} If you want the repository anyway, tell me and I'll upload it. |
Hi again @himself65. I have another problem related to monorepo, maybe is different to this issue so if you want I open another issue, tell me and I will do it. The problem is that if I import "react" from another package in a monorepo setup then throws the follow error:
The configuration is the same but futhermore of import "stylex" now this component import "react" too. |
vite specific issue, toeverything/blocksuite#304 |
My suggestion to fix this to use resolve.alias |
@emilgpa I think the last version of waku might resolve this. Let us know. |
@Aslemammad I get the same error in console. In the browser is: |
Ok, I'll check this today! Can you prepare a reproduction meanwhile (preferably Stackblitz)? |
The issue is (which I don't know if it's your configuration that causes it, or waku or even vite) but: "use client"
import stylex from "@stylexjs/stylex"
import React from "react"
console.log('React', React)
const styles = stylex.create({
base: {
color: "red"
}
}) And it logs React, but the rsc one: React {
Children: {
map: [Function: mapChildren],
forEach: [Function: forEachChildren],
count: [Function: countChildren],
toArray: [Function: toArray],
only: [Function: onlyChild]
},
Fragment: Symbol(react.fragment),
Profiler: Symbol(react.profiler),
StrictMode: Symbol(react.strict_mode),
Suspense: Symbol(react.suspense),
__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: {
ReactCurrentDispatcher: { current: null },
ReactCurrentOwner: { current: null },
ReactDebugCurrentFrame: {
setExtraStackFrame: [Function (anonymous)],
getCurrentStack: null,
getStackAddendum: [Function (anonymous)]
}
},
__SECRET_SERVER_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: { ReactCurrentCache: { current: null } },
cache: [Function: cache],
cloneElement: [Function: cloneElement],
createElement: [Function: createElement],
createRef: [Function: createRef],
forwardRef: [Function: forwardRef],
isValidElement: [Function: isValidElement],
lazy: [Function: lazy],
memo: [Function: memo],
startTransition: [Function: startTransition],
use: [Function: use],
useCallback: [Function: useCallback],
useDebugValue: [Function: useDebugValue],
useId: [Function: useId],
useMemo: [Function: useMemo],
version: '18.3.0-canary-670811593-20240322'
}
So there's no useEffect for the Heading.tsx component. Maybe Waku has a problem identifying Client components outside of the root. I have to not that this issue consists of two sub-issues. |
Thanks for the investigation. I would like to understand the condition better:
|
It happens on DEV and PRD too. |
Not sure, but may or may not be related: #633 (comment) (edit) it isn't related.
Confirmed. |
Yes, it's an issue with RSC. |
For
I think it applies to DEV too, so it's basically "2- After using the temporary solution, waku has hard time identifying Heading.tsx as a client component." split into two issues. |
#646 should fix it. |
What's remaining:
It's probably a dev only issue.
It's probably a bundling issue. |
Not sure if this is related (or if its even a bug): Our setup is a monorepo with a react ui library shared between multiple applications. When trying to import a component marked with When trying to reproduce the same scenario in the Waku monorepo, it failed with the very clear error message (#684):
I the project setup though, it failed much more cryptic message spotted in #676
That makes me think this line ...
react-server-dom-webpack being in a parent node_modules folder?
|
I'm aware it's a brittle hack. You can confirm if it causes the error by looking at your code in dist. |
In the first case, there is no And in the second, I don't have proof. All I know is that it went away with adding the dependency. And the error message from #676 ...
... seems to be related to the Maybe we can resolve to the absolute path of the package first and import from there? |
After writing this, I realized that this could be |
Here is a fixed version (https://github.com/himself65/waku-monorepo-example) I think the reason is vite threat them as two module and cause some bundle issues |
I think we can close this issue since https://github.com/himself65/waku-monorepo-example has fixed it for #676, I think this is a separate issue /cc @dai-shi |
@himself65 What's the tldr of the fix? |
making sure |
Otherwise package manager will link them in different directories and cause the bundler make them different |
@himself65 It's strange because the link I posted at the time with the monorepo as an example has the same version in The diff that I see is:
And maybe another thing. Maybe is something of this list? |
Oh, and the |
I updated to react to |
👍 |
file located in
monorepo/ui/components/Example/Example.tsx
file located in
monorepo/web/src/root-layout.tsx
When load the page in browser I get the follow error:
In this example I use stylex but It occurs with any external packages. The external package in the same package works but if it is loaded from another package in the same monorepo then it fails with that message error.
The text was updated successfully, but these errors were encountered: