remark-mdx esm nodes not being detected
See original GitHub issueInitial checklist
- I read the support docs
- I read the contributing guide
- I agree to follow the code of conduct
- I searched issues and couldn’t find anything (or linked relevant results below)
Affected packages and versions
latest
Link to runnable example
No response
Steps to reproduce
import { remark } from "remark";
import remarkMdx from "remark-mdx";
import type { Root } from "mdast";
import { remove } from "unist-util-remove";
const removeImports = () => {
return (tree: Root) => {
remove(tree, (node) => {
return (
node.type === "mdxjsEsm" &&
node?.value &&
node?.value.startsWith("import")
);
});
return tree;
};
};
export const preParseMdx = async (content: string): Promise<string> => {
const file = await remark()
.use(remarkMdx)
.use(removeImports)
.process(content);
return String(file);
};
const content = `
import test1 from 'test1'
import test2 from 'test2'
import test3 from 'test3'
TEXT POST IMPORTS!!!!!!!!
`;
await preParseMdx(content);
Expected behavior
Due to the custom plugin imports should be removed after running the above code. This made me suspect that the esm nodes are not being detected properly, but inside the remark-mdx package readme it says that it is.
Actual behavior
The import statements aren’t being detected and are labeled as type: "text"
and not type: "mdxjsEsm"
Runtime
Node v17
Package manager
npm v8
OS
macOS
Build and bundle tools
No response
Issue Analytics
- State:
- Created a year ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
ESM in Gatsby · Issue #40 · wooorm/xdm - GitHub
Is it possible to use this library with Gatsby? I can't seem to import xdm in Gatsby. The following gatsby-node.js file: (async function() ......
Read more >Troubleshooting MDX
This article goes through several common problems and errors that might occur when using MDX.
Read more >Can't require remark and rehype plugins for gatsby-plugin-mdx
I've made a little bit of research and I found that dynamic imports are not supported because you can't access the value in...
Read more >gatsby-plugin-mdx - npm
Use an older version of the remark-* / rehype-* package that is not ESM. Example: remark-gfm needs to be installed like this: npm...
Read more >Creating a Remark Transformer Plugin - Gatsby
To make gatsby-plugin-mdx recognize a local plugin like gatsby-remark-purple-headers , you need to point to its location in the project through require.resolve ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@wooorm Thanks for the insight Titus. This was 100% what was going on.
Strange indeed. https://mdxjs.com/community/support/ offers some ideas. In particular creating a sandbox with a runnable example of the issue you are seeing may help folks offer more concrete suggestions.