relay: Error: The macro you imported from "undefined" is being executed outside the context of compilation with babel-plugin-macros
Trying to use babel-plugin-relay/macro
with custom-react-scripts
Rendering Test component into index page:
import {QueryRenderer} from 'react-relay';
import graphql from 'babel-plugin-relay/macro';
const Test = () => <QueryRenderer
environment={environment}
query={graphql'
...
'}
render={() => {
return <div>test</div>;
}}
/>
Throws:
Uncaught Error: The macro you imported from “undefined” is being executed outside the context of compilation with babel-plugin-macros. This indicates that you don’t have the babel plugin “babel-plugin-macros” configured correctly. Please see the documentation for how to configure babel-plugin-macros properly
Even though I configured my .babelrc:
{
"presets": [
"es2015",
"stage-0",
"react"
],
"plugins": [
"relay",
"macros"
]
}
Repository I am using trying setup relay on: https://github.com/gothinkster/react-mobx-realworld-example-app
Package.json devDeps:
"devDependencies": {
"babel-plugin-relay": "^2.0.0-rc.2",
"babel-plugin-macros": "^2.5.0",
"custom-react-scripts": "0.2.0",
"relay-compiler": "^2.0.0"
}
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 5
- Comments: 19 (5 by maintainers)
I found this issue while trying to fix the exact same problem in a completely different context (A Next.js app).
I was able to fix my problem adding a
.babelrc
file with this:Not sure if it’ll help y’all, but leaving it here anyway.
I was getting the same error with next.js and @j0lv3r4’s fix didn’t help. However it worked after replacing
.babelrc
withbabel.config.js
containing:I am also experiencing the same issue with ts-jest and next.js. adding
preval
andmacros
to babelrc did not resolve my issue@sibelius
The repo you give is showing the exact error reported. I am here since I am facing the same issue when I am using penv.macro
I am experiencing the same issue with Next JS. I have tried this approach and that approach but they are not helping.
@adam-hanna I am also getting this error with ts-jest despite adding a .babelrc file as suggested by @j0lv3r4
If it adds to the discussion, I’m also experiencing this error but only with
ts-jest
. My app runs fine on its own.the error is on codesandbox itself https://github.com/codesandbox/codesandbox-client/issues/1604