Skip to content

Compilation error when transforming codes with forwardRef introduced #29

Open
@billstark001

Description

@billstark001

I cannot reproduce the issue stably (it does not occur in all cases), but the error message when it does occur is:

./node_modules/@wyw-in-js/transform/lib/module.js:225
      throw new EvalError(`${e.message} in${this.callstack.join('\n| ')}\n`);

EvalError: Unable to import "async_hooks". Importing Node builtins is not supported in the sandbox. in ./node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js
| ./node_modules/next/dist/server/route-modules/app-page/module.compiled.js
| ./node_modules/next/dist/server/route-modules/app-page/vendored/ssr/react.js
| ./src/(some component source with forwardRef and styled Linaria components).tsx

The package.json file looks like:

{
  "dependencies": {
    "@linaria/core": "^6.2.0",
    "@linaria/react": "^6.2.1",
    "@wyw-in-js/babel-preset": "^0.5.5",
    "next": "^15.1.4",
    "next-with-linaria": "^0.7.0",
    "react": "^19",
    "react-dom": "^19",
    "react-icons": "^5.4.0"
  },
  "devDependencies": {
    "@types/node": "^22",
    "@types/react": "19.0.4",
    "@types/react-dom": "^19",
    "autoprefixer": "^10.4.20",
    "eslint": "^9",
    "eslint-config-next": "15.1.4",
    "postcss": "^8",
    "prettier": "^3.4.2",
    "typescript": "5.7.3"
  }
}

Seems like the node builtin module async_hooks is occasionally imported by Next.js if forwardRef is used.

A temporary workaround will be separating styled components and reference-forwarded components into 2 different files. In this way, the error will not be triggered in the transformation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions