-
Notifications
You must be signed in to change notification settings - Fork 261
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
I got _JSXStyle is not defined with 3.4.0 #695
Comments
Does this happen in 3.3.3? We need a minimal reproducing test case, please! |
no, only happens when using addDefault from @babel/helper-module-imports |
cc @jaydenseric |
Upgrade some other build deps
I am facing the same issue too , we are forcing styled/jsx to version 3.3.0 because 3.4.0 will break the styles |
If this helps narrow down the bug hunt, I also just ran into this attempting to go from "env": {
"test": {
"presets": [
[
"@babel/preset-env",
{
"corejs": 2,
"shippedProposals": true,
"useBuiltIns": "usage"
}
]
]
}
},
"plugins": [
"styled-jsx/babel"
],
"presets": [
"@babel/preset-react"
] |
Having the same issue in a CRA project using mobx-react. As soon as I wrap a component in observer() I get an error saying _JSXStyle is not defined. Works fine before the component is wrapped. |
I got error |
Nothing is actionable without a minimum reproduction, ideally a Babel REPL link. Here is one to get started with: |
This is an example: |
It might be worth noting that when I encountered the issue, not all files were incorrect. A few compiled files correctly read I tried to deduce what the differences between those files were that might be the case. It occurred to me in this project/commit when running |
I'm running into this too. I just set up a fresh new project and noticed I removed object deconstruction from one of the components and it worked. Here's the generated component code with object deconstruction in the function signature: var Item = function Item(_ref) {
var img = _ref.img;
return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_1__.createElement("li", {
className: "jsx-3704275120"
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_1__.createElement("dl", {
className: "jsx-3704275120"
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_1__.createElement("dt", {
className: "jsx-3704275120"
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_1__.createElement("img", {
src: img,
className: "jsx-3704275120"
})), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_1__.createElement("dd", {
className: "jsx-3704275120"
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_1__.createElement("a", {
href: "#",
className: "jsx-3704275120"
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_1__.createElement("span", {
className: "jsx-3704275120"
}, "Find out more")))), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_1__.createElement(_JSXStyle, {
id: "3704275120"
}, "li.jsx-3704275120{padding:0;}img.jsx-3704275120{width:100%;}dd.jsx-3704275120{margin:1em;text-align:center;width:100%;}span.jsx-3704275120{border-radius:0.5em;background-color:skyblue;padding:0.5em 3em 0.5em 3em;}\n"));
}; And here's the result without: var Item = function Item(props) {
return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_1__.createElement("li", {
className: "jsx-3704275120"
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_1__.createElement("dl", {
className: "jsx-3704275120"
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_1__.createElement("dt", {
className: "jsx-3704275120"
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_1__.createElement("img", {
src: props.img,
className: "jsx-3704275120"
})), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_1__.createElement("dd", {
className: "jsx-3704275120"
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_1__.createElement("a", {
href: "#",
className: "jsx-3704275120"
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_1__.createElement("span", {
className: "jsx-3704275120"
}, "Find out more")))), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_1__.createElement(styled_jsx_style__WEBPACK_IMPORTED_MODULE_0__.default, {
id: "3704275120"
}, "li.jsx-3704275120{padding:0;}img.jsx-3704275120{width:100%;}dd.jsx-3704275120{margin:1em;text-align:center;width:100%;}span.jsx-3704275120{border-radius:0.5em;background-color:skyblue;padding:0.5em 3em 0.5em 3em;}\n"));
}; Notice how |
Interesting, though I'm experiencing it with class-based components without any deconstruction. |
Yep, can confirm this regression seems to have been introduced between v3.3.2 and v3.3.3. That corresponds to this commit: eb65f35 (PR #684, fixing issue #680). Maybe this bit? diff --git a/src/_utils.js b/src/_utils.js
index fafc0c2..007f1dc 100644
--- a/src/_utils.js
+++ b/src/_utils.js
@@ -1,4 +1,5 @@
import path from 'path'
+import { addDefault } from '@babel/helper-module-imports';
import * as t from '@babel/types'
import _hashString from 'string-hash'
import { SourceMapGenerator } from 'source-map'
@@ -621,14 +622,12 @@ export const booleanOption = opts => {
}
export const createReactComponentImportDeclaration = state => {
- const styleModule =
+ addDefault(
+ state.file.path,
typeof state.opts.styleModule === 'string'
? state.opts.styleModule
- : 'styled-jsx/style'
-
- return t.importDeclaration(
- [t.importDefaultSpecifier(t.identifier(STYLE_COMPONENT))],
- t.stringLiteral(styleModule)
+ : 'styled-jsx/style',
+ { nameHint: STYLE_COMPONENT}
)
} |
We'll have to revert #684 if a contributor isn't able to figure out how to fix this otherwise! Does anyone want to take an attempt at fixing this? |
Hi, when using mobx-react-light observer function will cause this problem |
solve this problem when using mobx by extracting components export class UiState {
num = 10
constructor() {
makeAutoObservable(this)
}
}
export const useUiState=new UiState()
type HahaProps = {
uiState: UiState
}
export const Foo = observer((props:HahaProps)=>{
const state = props.uiState;
return (
<>
<h1>
{state.num}
</h1>
<style jsx>
{`
h1 {
color: red;
}`}
</style>
</>
)
}) after const FooComponent = (props: HahaProps) => {
const state = props.uiState;
return (
<>
<h1>
{state.num}
</h1>
<style jsx>
{`
h1 {
color: red;
}`}
</style>
</>
)
}
export const Foo = observer(FooComponent) |
@Timer This does not affect current users, it is just for those who want to avoid this issue, perhaps you have other solutions and would like to hear your ideas. |
Hey guys, I ran into a similar issue and just found a workaround for my use case. Hopefully it can shed a light on yours? TL;DRimport _JSXStyle from 'styled-jsx/style';
if (typeof global !== 'undefined') {
Object.assign(global, { _JSXStyle })
} More contextI was actually trying to import a component from a local package (yarn workspaces + lerna setup) that had Next app (website)
|
🎉 This issue has been resolved in version 3.4.5 🎉 The release is available on: Your semantic-release bot 📦🚀 |
👋 friend. Welcome to styled-jsx and thanks for contributing!
If you need help or have a question about styled-jsx please ask it on Spectrum https://spectrum.chat/styled-jsx or join our Slack community at https://zeit.chat and ask it in the
#next
channel.Before you open a new issue please take a look at our Frequent Asked Questions and open issues.
Remember, often time asking in chat or looking at the FAQ/issues can be faster than waiting for us to reply to a new issue*.
If you are here to report a bug or request a feature please remove this introductory section and fill out the information below!
Do you want to request a feature or report a bug?
What is the current behavior?
when I use <style jsx> in MyComponent I got _JSXStyle is not defined
If the current behavior is a bug, please provide the steps to reproduce and possibly a minimal demo or testcase in the form of a Next.js app, CodeSandbox URL or similar
What is the expected behavior?
Environment (include versions)
Did this work in previous versions?
yes
The text was updated successfully, but these errors were encountered: