Skip to content

Build error with NextJs #3502

@alex289

Description

@alex289
  • Check if updating to the latest Preact version resolves the issue

Using Next.js -> package.json:

"next": "12.1.2",
"preact": "^10.7.0",
"react": "18.0.0",
"react-dom": "18.0.0"

Describe the bug
I am using Preact to replace React with webpacks alias config. After upgrading to React 18 I get following error when I try to build:

./node_modules/next/dist/client/index.js
Module not found: Package path ./compat/client is not exported from package path\to\project\node_modules\preact (see exports field in path\to\project\node_modules\preact\package.json)

(I removed personal data from the path)

To Reproduce

Steps to reproduce the behavior:

  1. Create a NextJs project: yarn create next-app --typescript
  2. Add preact: yarn add preact
  3. Change next.config.js to:
/** @type {import('next').NextConfig} */
const nextConfig = {
  reactStrictMode: true,
  swcMinify: true,
  webpack: (config, { dev, isServer }) => {
    if (!dev && !isServer) {
      // Replace React with Preact only in client production build
      Object.assign(config.resolve.alias, {
        'react/jsx-runtime.js': 'preact/compat/jsx-runtime',
        react: 'preact/compat',
        'react-dom/test-utils': 'preact/test-utils',
        'react-dom': 'preact/compat',
      });
    }

    return config;
  },
};

module.exports = nextConfig;
  1. Run: yarn build

Expected behavior
Build should succeed without errors.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions