-
Notifications
You must be signed in to change notification settings - Fork 135
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
getting "The macro imported from "../macro" must be wrapped in "createMacro" which you can get from "babel-plugin-macros"" even though I DID wrap it #71
Comments
Hi @tsiq-swyx! I'm fairly confident all you need to do is: module.exports = createMacro(bladeMacro) And it'll work. A macro should only have an export that is a function wrapped in |
just tried this: const { createMacro, MacroError } = require('babel-plugin-macros');
// const {getReplacement} = require('./helpers')
const { handleCreateRazor } = require('./index');
module.exports = createMacro(bladeMacros);
function bladeMacros({ references, state, babel: { types: t } }) {
references.createQuery.forEach(referencePath => {
handleCreateRazor(referencePath, t);
});
references.createFragment.forEach(referencePath => {
handleCreateRazor(referencePath, t);
})`;`;
} did not work I am afraid. I actually suspect the error message is wrong here! as I've tried quite a few combinations and nothing has worked. :( I also tried this (inspired by how emotion does it) module.exports = createMacro(bladeMacros);
function bladeMacros({ references, state, babel: { types: t } }) {
Object.keys(references).forEach(referenceKey => {
if (referenceKey === 'createQuery' || referenceKey === 'createFragment') {
references[referenceKey].forEach(referencePath => {
handleCreateRazor(referencePath, t);
});
} else throw new MacroError('invalid require?');
});
} to no avail. repro in the link above, just if I were to debug this I probably have to go into the code of babel-plugin-macros... will leave that to another day. |
kent suggested via twitter that this may be a testing-only issue: "I've seen situations where plugins are loaded twice in testing when doing babel plugin testing and it can be.... a problem" I built it (http://npm.im/blade.macro) and tried it out in a sample app and it doesnt give this error, it just doesnt work at all, but i am not sure if i am doing this right (since the thing is untested to work in the first place). |
confirmed that it is a test-only issue. here is the macro running in astexplorer http://astexplorer.net/#/gist/4b72d63ecd01237e179c102f6df9c2b4/31b569284fb12ba8761dc25d75db45d0ec05eba8 and it is still throwing this same error in the test. i think the error message is simply wrong somehow.
|
Yep, my guess is that it's applying babel-plugin-macros twice or something. This is very hard to debug, but I think you may be able to solve the problem by adding a |
just tried adding a
no difference at all unfortunately. |
Boo! Hmmm.... I've no idea. What happens if you try to test it manually without using babel-plugin-tester? |
i confess i have no idea how to do that 😂 i will look into it. for the time being, i am doing the fabled "test in prod" protocol and it is working at least so yay! |
Luckily your macro logic is fairly simple so I think you'll be ok with that approach! |
ok well feel free to close if not helpful, i dont feel like we're going to
track this one down anytime soon.
…On Wed, Jul 11, 2018 at 10:38 PM Kent C. Dodds ***@***.***> wrote:
Luckily your macro logic is fairly simple so I think you'll be ok with
that approach!
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#71 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AiT1ghd7OArS4bO4M3DxUvE8jwUXwLSTks5uFraWgaJpZM4VKdxi>
.
|
Yeah, I'll go ahead and close this. If I or anyone else bumps into this again we can re-open. |
Hello! really excited to make my first macro! just some minor issues and i suspect a wrong error message...
babel-plugin-macros
version: 2.2.1node
version: 9.4.0npm
(oryarn
) version: 6.1.0Relevant code or config
and my fixture code:
What you did:
What happened:
Reproduction repository:
https://github.com/sw-yx/babel-blade/blob/macrosIs/packages/babel-plugin-blade/src/macro.js
Problem description: I want to do named exports similar to emotion (related issue: #5) - however it is somehow not working and i suspect the error message might be wrong? i really am not sure what to do here.
Suggested solution: not sure at all. i tried looking at how Emotion does it, thats what my solution is based on.
The text was updated successfully, but these errors were encountered: