question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

remark-mdx esm nodes not being detected

See original GitHub issue

Initial checklist

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:closed
  • Created a year ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
hahnbeeleecommented, Oct 28, 2022

@wooorm Thanks for the insight Titus. This was 100% what was going on.

1reaction
ChristianMurphycommented, Oct 27, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found