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

Package subpath './compat/jsx-runtime.js' is not defined by "exports" in preact/package.json #52

Open
1 task done
heyitsarpit opened this issue Jan 8, 2022 · 1 comment

Comments

@heyitsarpit
Copy link

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

Package subpath './compat/jsx-runtime.js' is not defined by "exports" in preact/package.json

I'm using preact in next js and tried updating to next 12, I'm using mdx-bundler which import "react/jsx-runtime" internally.

Error :

error - ./node_modules/mdx-bundler/dist/client.js:11:0
Module not found: Package path ./compat/jsx-runtime.js is not exported from package /Users/arpit/Developer/personal_website/node_modules/preact (see exports field in /Users/arpit/Developer/personal_website/node_modules/preact/package.json)

Import trace for requested module:
./node_modules/mdx-bundler/client/index.js
./pages/index.tsx

https://nextjs.org/docs/messages/module-not-found
error - Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './compat/jsx-runtime.js' is not defined by "exports" in /Users/arpit/Developer/personal_website/node_modules/preact/package.json

When I check the node_modules, I can see that "jsx-runtime" is inclued in the exports field.

	"exports": {
...
		"./jsx-runtime": {
			"browser": "./jsx-runtime/dist/jsxRuntime.module.js",
			"umd": "./jsx-runtime/dist/jsxRuntime.umd.js",
			"require": "./jsx-runtime/dist/jsxRuntime.js",
			"import": "./jsx-runtime/dist/jsxRuntime.mjs"
		},
		"./jsx-dev-runtime": {
			"browser": "./jsx-runtime/dist/jsxRuntime.module.js",
			"umd": "./jsx-runtime/dist/jsxRuntime.umd.js",
			"require": "./jsx-runtime/dist/jsxRuntime.js",
			"import": "./jsx-runtime/dist/jsxRuntime.mjs"
		},
...
}
@idirmosh
Copy link

I had the same issue. as a temporary fix you can assign react/jsx-runtime.js to preact/jsx-runtime in your next.config.js file.

// next.config.js
  webpack: (config, options) => {
    if (!options.dev && !options.isServer) {
      Object.assign(config.resolve.alias, {
      // assign react/jsx-runtime.js to preact/jsx-runtime
        'react/jsx-runtime.js': 'preact/compat/jsx-runtime',
        react: 'preact/compat',
        'react-dom/test-utils': 'preact/test-utils',
        'react-dom': 'preact/compat',
      });
    }

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

No branches or pull requests

2 participants