waku: fail to resolve packages imported from another package in a monorepo

file located in monorepo/ui/components/Example/Example.tsx

import stylex from "@stylexjs/stylex"

const styles = stylex.create({
    base: {
        borderRadius: 40,
    },
})

export const Example = () => {
    return (
        <div {...stylex.props(styles.base)}>
            <h1>Example</h1>
        </div>
    )
}

file located in monorepo/web/src/root-layout.tsx

import { Example } from "@my-org/ui/components/Example/Example"
import stylex from "@stylexjs/stylex"

const styles = stylex.create({
    base: {
        padding: 10,
    },
})

export const RootLayout = async ({ children }: RootLayoutProps) => {
    return (
        <div id="__waku">
            <Header />
            <main>
                  <Example />
                  <div {...stylex.props(styles.base)}>
                      {children}
                  </div>
            </main>
            <Footer />
        </div>
    )
}

When load the page in browser I get the follow error:

Error: Error: Failed to load url ../../@stylexjs/stylex (resolved id: ../../@stylexjs/stylex) in ...

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.

About this issue

  • Original URL
  • State: open
  • Created 5 months ago
  • Comments: 26 (20 by maintainers)

Most upvoted comments

While I was preparing a repo for you to try, I already know what causes it. In the tsconfig.json of the the package consumed (in this example, ui) by the other package (in this example, web) is set the property baseUrl to ".". The tsconfig.json is:

{
    "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.

It happens on DEV and PRD too.