Skip to content
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

Build error with NextJs #3502

Closed
1 task done
alex289 opened this issue Mar 30, 2022 · 3 comments · Fixed by #3506
Closed
1 task done

Build error with NextJs #3502

alex289 opened this issue Mar 30, 2022 · 3 comments · Fixed by #3506

Comments

@alex289
Copy link

alex289 commented Mar 30, 2022

  • 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.

@developit
Copy link
Member

What is the reason for having React 18 installed alongside Preact?

@alex289
Copy link
Author

alex289 commented Mar 30, 2022

@developit I use React while developing and only replace it with Preact in production.

@badaczewski
Copy link

badaczewski commented Apr 1, 2022

I'm having the same issue from within my GatsbyJS project after upgrading to React 18.

Module not found: Error: Package path ./compat/client is not exported from package D:\XXX\XXX\node_modules\preact (see exports field in D:\XXX\XXX\node_modules\preact\package.json)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants