Skip to content

Not working with Vue 3 #1718

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

Closed
jannikbuscha opened this issue Oct 6, 2021 · 23 comments · Fixed by #1759
Closed

Not working with Vue 3 #1718

jannikbuscha opened this issue Oct 6, 2021 · 23 comments · Fixed by #1759
Labels
🙋 no/question This does not need any changes

Comments

@jannikbuscha
Copy link

Not working with Vue 3

When I create a Project like this: https://github.com/mdx-js/mdx/tree/master/examples/vue with Vue 3, I get this warning:
image

Also nothing happens

@wooorm
Copy link
Member

wooorm commented Oct 6, 2021

xdm works now with vue 3: https://github.com/wooorm/xdm#vue.
This project will support it in ± 4 weeks maybe.

@jannikbuscha
Copy link
Author

xdm works now with vue 3: https://github.com/wooorm/xdm#vue. This project will support it in ± 4 weeks maybe.

Thank you 👍

@jannikbuscha
Copy link
Author

i saw that you have customized the docs and i wanted to test now already and i get this error with the vue.config.js configuration currently:
image

image

@wooorm
Copy link
Member

wooorm commented Oct 17, 2021

and i wanted to test now already

The docs have been updated but the code has not been published.


Are you using Vue 3 with Vue CLI?


Can you swap out @mdx-js/loader with xdm/webpack.cjs to see if that still fails, and if so, make a reproduction?

@jannikbuscha
Copy link
Author

and i wanted to test now already

The docs have been updated but the code has not been published.

Are you using Vue 3 with Vue CLI?

Can you swap out @mdx-js/loader with xdm/webpack.cjs to see if that still fails, and if so, make a reproduction?

i still get the error.

I use vue cli with this configuration:
image

@ChristianMurphy
Copy link
Member

@jannikbuscha could you share a complete example of what you tried in a codesandbox? https://vue.new

@jannikbuscha
Copy link
Author

@jannikbuscha could you share a complete example of what you tried in a codesandbox? https://vue.new

https://codesandbox.io/s/cool-breeze-e66xz?file=/src/App.vue

@jannikbuscha
Copy link
Author

I have found the config error. You have to use end() when working with multiple loaders:
image

However, the MDXProvider does not work completely:
image

@wooorm
Copy link
Member

wooorm commented Oct 19, 2021

Nice catch. Can I interest you in a fix for the docs?
And can you elaborate on the vue context API not working?

@wooorm
Copy link
Member

wooorm commented Oct 20, 2021

For the second part: that’s because you have not configured @mdx-js/loader to use @mdx-js/vue:

.options({jsx: true, providerImportSource: '@mdx-js/vue' /* otherOptions… */})

wooorm added a commit that referenced this issue Oct 20, 2021
wooorm added a commit that referenced this issue Oct 20, 2021
@jannikbuscha
Copy link
Author

For the second part: that’s because you have not configured @mdx-js/loader to use @mdx-js/vue:

.options({jsx: true, providerImportSource: '@mdx-js/vue' /* otherOptions… */})

In my ide i get this error:
image

and codesandbox (https://codesandbox.io/s/heuristic-lovelace-rim55?file=/src/App.vue):
image

here my repo:
https://github.com/jannikbuscha/mdx-vue3

@wooorm
Copy link
Member

wooorm commented Oct 20, 2021

Trying out your repo works perfectly for me, no errors.
Even if I add Post to the template or both Post and MDXProvider:

diff --git a/src/App.vue b/src/App.vue
index eee837e..1bcf76e 100644
--- a/src/App.vue
+++ b/src/App.vue
@@ -1,5 +1,6 @@
 <template>
   <h1>Test</h1>
+  <MDXProvider v-bind:components="components"><Post /></MDXProvider>
 </template>
 
 <script lang="ts">
@@ -9,6 +10,9 @@ import {MDXProvider} from '@mdx-js/vue'
 import Post from './post.mdx'
 
 @Options({
+  data() {
+    return { components: { h1: "h2" } };
+  },
   components: {
     MDXProvider, Post
   },

If your IDE is breaking, that’s likely due to it not supporting ESM. See: https://v2.mdxjs.com/docs/troubleshooting-mdx/#problems-integrating-mdx. It’s a problem they should fix.


For codesandbox, something is going wrong there indeed. You can add a console.log(Post) under its import, and see that it’s just a plain text string.
I am guessing that it is due to another integration?

@jannikbuscha
Copy link
Author

Trying out your repo works perfectly for me, no errors. Even if I add Post to the template or both Post and MDXProvider:

diff --git a/src/App.vue b/src/App.vue
index eee837e..1bcf76e 100644
--- a/src/App.vue
+++ b/src/App.vue
@@ -1,5 +1,6 @@
 <template>
   <h1>Test</h1>
+  <MDXProvider v-bind:components="components"><Post /></MDXProvider>
 </template>
 
 <script lang="ts">
@@ -9,6 +10,9 @@ import {MDXProvider} from '@mdx-js/vue'
 import Post from './post.mdx'
 
 @Options({
+  data() {
+    return { components: { h1: "h2" } };
+  },
   components: {
     MDXProvider, Post
   },

If your IDE is breaking, that’s likely due to it not supporting ESM. See: https://v2.mdxjs.com/docs/troubleshooting-mdx/#problems-integrating-mdx. It’s a problem they should fix.

For codesandbox, something is going wrong there indeed. You can add a console.log(Post) under its import, and see that it’s just a plain text string. I am guessing that it is due to another integration?

yes it seems like my ide is causing some problems. I have now tested the whole thing with gitpod and so far everything works. The question I have now is, how do I build something like gfm with the MDXProvider component? if I do that as in the vue example then I get the following error:
image
image

@wooorm
Copy link
Member

wooorm commented Oct 20, 2021

You’re attempting to run Vue inside Vue and MDX inside MDX. You don’t have to!
You’re using MDX through [@mdx-js/loader](https://v2.mdxjs.com/packages/loader/. You can configure that. Pass remarkGfm there. In the place where you’re using @mdx-js/loader.

@jannikbuscha
Copy link
Author

You’re attempting to run Vue inside Vue and MDX inside MDX. You don’t have to! You’re using MDX through [@mdx-js/loader](https://v2.mdxjs.com/packages/loader/. You can configure that. Pass remarkGfm there. In the place where you’re using @mdx-js/loader.

I don't think I really understand this yet. Where exactly does this need to be configured? I have now tried the two things in my vue.config.js:
image
image

@wooorm
Copy link
Member

wooorm commented Oct 20, 2021

Before, you tried to import it. That’s what you have to do again. That’s what’s shown in the guide: https://v2.mdxjs.com/guides/gfm/.

import remarkGfm from 'remark-gfm'
// ...
.options({jsx: true, remarkPlugins: [remarkGfm]})

If you removed that because you were getting errors that you were not allowed to import things, then you can see the ESM troubleshooting I linked to earlier for more info and ask Vue CLI folks for help. ESM in vue.config.js seems to be supported since April already, though maybe it’s in beta: https://v2.mdxjs.com/docs/extending-mdx/#using-plugins

@jannikbuscha
Copy link
Author

Before, you tried to import it. That’s what you have to do again. That’s what’s shown in the guide: https://v2.mdxjs.com/guides/gfm/.

import remarkGfm from 'remark-gfm'
// ...
.options({jsx: true, remarkPlugins: [remarkGfm]})

If you removed that because you were getting errors that you were not allowed to import things, then you can see the ESM troubleshooting I linked to earlier for more info and ask Vue CLI folks for help. ESM in vue.config.js seems to be supported since April already, though maybe it’s in beta: https://v2.mdxjs.com/docs/extending-mdx/#using-plugins

Thank you very much for your detailed help.
I have now opened a stackoverflow question regarding to the ESM story, because after a few hours I have not yet come to a solution.

@ChristianMurphy
Copy link
Member

@jannikbuscha have you seen vuejs/vue-cli#4477 and vuejs/vue-cli#6405?
It looks like vue.config.mjs should be supported.

@jannikbuscha
Copy link
Author

@jannikbuscha have you seen vuejs/vue-cli#4477 and vuejs/vue-cli#6405? It looks like vue.config.mjs should be supported.

i get this error:
image

@ChristianMurphy
Copy link
Member

ChristianMurphy commented Oct 20, 2021

vuejs/vue-cli#6592 (comment) might help? It looks like the loader isn't being applied.

@jannikbuscha
Copy link
Author

vuejs/vue-cli#6592 (comment) might help? It looks like the loader isn't being applied.

Then i get this error:
image

and with vue.config.mjs + export default {}
image

@wooorm
Copy link
Member

wooorm commented Oct 21, 2021

Your last screenshot is very close. However, as I mentioned before, while vue-cli added support for .mjs files, they have not released it. They are in beta.

Here’s how I can make your project work for me locally.

  1. First, let’s update dependencies. It’s always good when adding new dependencies (such as the this new MDX 2 RC), to make sure the rest is up to date:
diff --git a/package.json b/package.json
index 884779f..d2f602d 100644
--- a/package.json
+++ b/package.json
@@ -9,7 +9,6 @@
   },
   "dependencies": {
     "@mdx-js/loader": "^2.0.0-rc.1",
-    "@mdx-js/mdx": "^2.0.0-rc.1",
     "@mdx-js/vue": "^2.0.0-rc.1",
     "core-js": "^3.6.5",
     "remark-gfm": "^3.0.0",
@@ -17,16 +16,16 @@
     "vue-class-component": "^8.0.0-0"
   },
   "devDependencies": {
-    "@typescript-eslint/eslint-plugin": "^4.18.0",
-    "@typescript-eslint/parser": "^4.18.0",
+    "@typescript-eslint/eslint-plugin": "^5.1.0",
+    "@typescript-eslint/parser": "^5.1.0",
     "@vue/babel-plugin-jsx": "^1.1.1",
-    "@vue/cli-plugin-babel": "~4.5.0",
-    "@vue/cli-plugin-eslint": "~4.5.0",
-    "@vue/cli-plugin-typescript": "~4.5.0",
-    "@vue/cli-service": "~4.5.0",
+    "@vue/cli-plugin-babel": "5.0.0-beta.6",
+    "@vue/cli-plugin-eslint": "5.0.0-beta.6",
+    "@vue/cli-plugin-typescript": "5.0.0-beta.6",
+    "@vue/cli-service": "5.0.0-beta.6",
     "@vue/compiler-sfc": "^3.0.0",
-    "@vue/eslint-config-typescript": "^7.0.0",
-    "eslint": "^6.7.2",
+    "@vue/eslint-config-typescript": "^8.0.0",
+    "eslint": "^8.0.0",
     "eslint-plugin-vue": "^7.0.0",
     "typescript": "~4.1.5"
   }
  1. Next, make sure those updates are installed by running yarn in your terminal
  2. Then, rename vue.config.js in your repo to vue.config.mjs
  3. Now, running yarn serve runs the development server which shows that autolink literals, footnotes, strikethrough, tables, and tasklists are supported!

wooorm added a commit that referenced this issue Oct 21, 2021
@jannikbuscha
Copy link
Author

Your last screenshot is very close. However, as I mentioned before, while vue-cli added support for .mjs files, they have not released it. They are in beta.

Here’s how I can make your project work for me locally.

  1. First, let’s update dependencies. It’s always good when adding new dependencies (such as the this new MDX 2 RC), to make sure the rest is up to date:
diff --git a/package.json b/package.json
index 884779f..d2f602d 100644
--- a/package.json
+++ b/package.json
@@ -9,7 +9,6 @@
   },
   "dependencies": {
     "@mdx-js/loader": "^2.0.0-rc.1",
-    "@mdx-js/mdx": "^2.0.0-rc.1",
     "@mdx-js/vue": "^2.0.0-rc.1",
     "core-js": "^3.6.5",
     "remark-gfm": "^3.0.0",
@@ -17,16 +16,16 @@
     "vue-class-component": "^8.0.0-0"
   },
   "devDependencies": {
-    "@typescript-eslint/eslint-plugin": "^4.18.0",
-    "@typescript-eslint/parser": "^4.18.0",
+    "@typescript-eslint/eslint-plugin": "^5.1.0",
+    "@typescript-eslint/parser": "^5.1.0",
     "@vue/babel-plugin-jsx": "^1.1.1",
-    "@vue/cli-plugin-babel": "~4.5.0",
-    "@vue/cli-plugin-eslint": "~4.5.0",
-    "@vue/cli-plugin-typescript": "~4.5.0",
-    "@vue/cli-service": "~4.5.0",
+    "@vue/cli-plugin-babel": "5.0.0-beta.6",
+    "@vue/cli-plugin-eslint": "5.0.0-beta.6",
+    "@vue/cli-plugin-typescript": "5.0.0-beta.6",
+    "@vue/cli-service": "5.0.0-beta.6",
     "@vue/compiler-sfc": "^3.0.0",
-    "@vue/eslint-config-typescript": "^7.0.0",
-    "eslint": "^6.7.2",
+    "@vue/eslint-config-typescript": "^8.0.0",
+    "eslint": "^8.0.0",
     "eslint-plugin-vue": "^7.0.0",
     "typescript": "~4.1.5"
   }
  1. Next, make sure those updates are installed by running yarn in your terminal
  2. Then, rename vue.config.js in your repo to vue.config.mjs
  3. Now, running yarn serve runs the development server which shows that autolink literals, footnotes, strikethrough, tables, and tasklists are supported!

OMG! Thank you so much! 😄
image

@ChristianMurphy ChristianMurphy added 💬 type/discussion This is a request for comments 🙋 no/question This does not need any changes and removed 🐛 type/bug This is a problem 🔍 status/open 💬 type/discussion This is a request for comments labels Oct 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🙋 no/question This does not need any changes
Development

Successfully merging a pull request may close this issue.

3 participants