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: closed
  • Created 3 years ago
  • Comments: 35 (22 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.

I updated to react to 19. The error persists. Updated to waku 0.20.2 and the error was gone. Sorry for not trying it at the time, I was a little busy. It seems that the problem was solved a long time ago. I think this can be closed.

@himself65 It’s strange because the link I posted at the time with the monorepo as an example has the same version in react, react-dom and react-dom-server-webpack.

The diff that I see is:

  • react 19
  • new version waku
  • not exports property in ui package
  • module as nodenext in tsconfig of web package

And maybe another thing. Maybe is something of this list?

It happens on DEV and PRD too.