question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Preact: Package path ./compat/jsx-runtime.js is not exported from package

See original GitHub issue

Hello

I am having issues when replacing React with Preact in production build.

My project can be found at jahirfiquitiva/jahir.dev

And this is the build error I am getting:

info  - Creating an optimized production build  
Failed to compile.

./node_modules/next-contentlayer/dist/hooks/useMDXComponent.js
Module not found: Package path ./compat/jsx-runtime.js is not exported from package /Users/jahir/dev/jahir/website/node_modules/preact (see exports field in /Users/jahir/dev/jahir/website/node_modules/preact/package.json)

Import trace for requested module:
./node_modules/next-contentlayer/dist/hooks/index.js
./src/pages/blog/[slug].tsx


> Build failed because of webpack errors
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

I’m not sure why it started failing if it was working just fine before 😕

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
alany411commented, Dec 6, 2021

I found a temporary solution, if you want to use preact@10.6. You can edit your next.config.js to assign the correct alias until this issue gets fixed.

/** @type {import('next').NextConfig} */

const { withContentlayer } = require('next-contentlayer');

module.exports = withContentlayer()({
  reactStrictMode: true,
  swcMinify: true,
  webpack: (config, { dev, isServer }) => {
    if (!dev && !isServer) {
      Object.assign(config.resolve.alias, {
        'react/jsx-runtime.js': 'preact/compat/jsx-runtime',
        react: 'preact/compat',
        'react-dom': 'preact/compat',
        'react-dom/test-utils': 'preact/test-utils',
      });
    }

    return config;
  },
});
1reaction
jahirfiquitivacommented, Jan 3, 2022

Sure… Thanks for the help

Read more comments on GitHub >

github_iconTop Results From Across the Web

Runtime not exported · Issue #3465 · preactjs/preact - GitHub
Steps to reproduce the behavior: Add project with the provided package.json; See error. Expected behavior. Should run.
Read more >
how to fix this error when build next build - Stack Overflow
compat/jsx-runtime.js is not exported from package ... (see exports field in /vercel/path0/node_modules/preact/package.json).
Read more >
Use Preact in Next.js 13 - DEV Community ‍ ‍
Preact has a package named preact/compat to let developers use React libraries with Preact. Learn more about the differences of Preact from ...
Read more >
Switching to Preact (from React)
The preact-compat package provides all the necessary tweaks on top of Preact's core to make it work just like react and react-dom ,...
Read more >
assign arrow function to a variable before exporting as module ...
But why can't i do it the other way? ... Some might not allow you to export unnamed functions. ... compat/jsx-runtime.js is not...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found