Replies: 3 comments
-
|
Are you using custom binary? |
Beta Was this translation helpful? Give feedback.
-
|
Try importing React as React from 'react' |
Beta Was this translation helpful? Give feedback.
-
|
This happens because of a mismatch between JSX runtime mode and the import. You have two solutions: Solution 1: Use the new automatic JSX runtime (recommended) Remove the manual React import and configure SWC to use automatic runtime: {
"jsc": {
"transform": {
"react": {
"runtime": "automatic"
}
}
}
}Your code becomes: // No need to import React!
class A extends React.Component {
render() {
return <div>test</div>
}
}SWC will auto-inject Solution 2: Use classic runtime with pragma If you must use the classic {
"jsc": {
"transform": {
"react": {
"runtime": "classic",
"pragma": "React.createElement",
"pragmaFrag": "React.Fragment"
}
}
}
}And keep your import: import React from 'react';Why this happens: SWC's default JSX transform uses Using |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
The error
React is not definedoccurs because SWC renames theimport React from 'react'toimport React1 from 'react'. How can I fix this?input:
expected:
got:
Beta Was this translation helpful? Give feedback.
All reactions