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

SyntaxError while importing react-dom / react #16

Open
p-sw opened this issue Jun 5, 2024 · 4 comments
Open

SyntaxError while importing react-dom / react #16

p-sw opened this issue Jun 5, 2024 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@p-sw
Copy link

p-sw commented Jun 5, 2024

Describe the bug
It throws SyntaxError everytime I load localhost:5314.

  <-- GET /
file:///home/shinwoo-park/WebstormProjects/ui-docs/dist/rsc/App.js:5
import ReactDOM, { createPortal } from 'react-dom';
                   ^^^^^^^^^^^^
SyntaxError: Named export 'createPortal' not found. The requested module 'react-dom' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'react-dom';
const { createPortal } = pkg;

    at ModuleJob._instantiate (node:internal/modules/esm/module_job:134:21)
    at async ModuleJob.run (node:internal/modules/esm/module_job:217:5)
    at async ModuleLoader.import (node:internal/modules/esm/loader:316:24)
    at async file:///home/shinwoo-park/WebstormProjects/ui-docs/node_modules/.pnpm/seia.js@file+..+seia+packages+seia+seia.js-0.1.2.tgz_@[email protected][email protected]_3adzscgslwpexx6cukdynv7xtu/node_modules/seia.js/dist/worker.js:11:20
  --> GET / 500 142ms

To Reproduce
Here is a repository I'm working on.

  1. Install dependencies
  2. Build (success without any error or warning)
  3. Start
  4. Open localhost:5314 -> Error

Expected behavior
Success with no error, or throws any error caused by react-router-dom

Desktop (please complete the following information):

  • OS: Linux, Ubuntu 22
  • Browser: Firefox
@p-sw
Copy link
Author

p-sw commented Jun 5, 2024

Minimal way to reproduce error

  1. mkdir minitest
  2. cd minitest
  3. pnpm init
  4. pnpm install [email protected] [email protected] seia.js
  5. pnpm add -D @types/node @types/react @types/react-dom vite typescript
  6. mkdir src
  7. touch src/App.tsx
  8. vim src/App.tsx
  9. add content to src/App.tsx:
import { createPortal } from "react-dom";

export default function App() {
  return createPortal(<div>Hello</div>, document.body);
}
  1. vim package.json
  2. add "type": "module"
  3. pnpm seia build
  4. pnpm seia start
  5. Get error
  <-- GET /
file:///home/shinwoo-park/Documents/projects/minitest/dist/rsc/App.js:1
import { createPortal } from 'react-dom';
         ^^^^^^^^^^^^
SyntaxError: Named export 'createPortal' not found. The requested module 'react-dom' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'react-dom';
const { createPortal } = pkg;

    at ModuleJob._instantiate (node:internal/modules/esm/module_job:134:21)
    at async ModuleJob.run (node:internal/modules/esm/module_job:217:5)
    at async ModuleLoader.import (node:internal/modules/esm/loader:316:24)
    at async file:///home/shinwoo-park/Documents/projects/minitest/node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected]_imdrh2fqohes5aqxcu753repva/node_modules/seia.js/dist/worker.js:11:20
  --> GET / 500 75ms

@abiriadev
Copy link
Owner

@p-sw Thank you for reporting! I reproduced the same issue, and I will immediately work on it.

@abiriadev abiriadev self-assigned this Jun 5, 2024
@abiriadev abiriadev added the bug Something isn't working label Jun 5, 2024
@abiriadev
Copy link
Owner

@p-sw It looks like you are trying to use createPortal in server components.

Will you try this instead?

'use client'

import { createPortal } from "react-dom";

export default function App() {
  return typeof document !== "undefined" ? createPortal(<div>Hello</div>, document.body) : null
}

@abiriadev
Copy link
Owner

Ah, one more. You need to add tsconfig.json at the root containing this line:

{
	"compilerOptions": {
		"jsx": "react-jsx"
	}
}

This is required since you manually setup your project with mkdir, and Vite's default JSX transform rule is react. I will make seia to use react-jsx by default later!

@abiriadev abiriadev added this to Seia Jun 7, 2024
@abiriadev abiriadev moved this to Todo in Seia Jun 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Todo
Development

No branches or pull requests

2 participants