brillout / vite-plugin-mdx

Vite Plugin for MDX
MIT License
111 stars 36 forks source link

Using this plugin with Vite SSR fails #13

Closed thelinuxlich closed 3 years ago

thelinuxlich commented 3 years ago

I don't know if it's specific to this plugin but when I try to run a simple static page with it using SSR it throws this error:

/home/thelinuxlich/frontend-starter/node_modules/@mdx-js/react/dist/esm.js:1
import React from 'react';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at wrapSafe (node:internal/modules/cjs/loader:1024:16)
    at Module._compile (node:internal/modules/cjs/loader:1072:27)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1137:10)
    at Module.load (node:internal/modules/cjs/loader:973:32)
    at Function.Module._load (node:internal/modules/cjs/loader:813:14)
    at Module.require (node:internal/modules/cjs/loader:997:19)
    at require (node:internal/modules/cjs/helpers:92:18)
    at Module.<anonymous> (/home/thelinuxlich/frontend-starter/dist/server/entry-server.js:24:14)
    at Module._compile (node:internal/modules/cjs/loader:1108:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1137:10)
brillout commented 3 years ago

What version are you using?

A working example: https://github.com/brillout/vite-plugin-ssr#markdown

thelinuxlich commented 3 years ago

I'm using latest. I don't want to use vite-plugin-ssr because it does too much :(

brillout commented 3 years ago

You can try to add it to ssr.noExternal, see https://vitejs.dev/guide/ssr.html#ssr-externals

because it does too much

In what way does vite-plugin-ssr do too much for you? What are you building?

vite-plugin-ssr may or may not be the right tool for you but note that, unlike Next.js, it doesn't tie your hands. The reason I built vite-plugin-ssr was because I wanted to use an SSR solution that doesn't take control away from me.

thelinuxlich commented 3 years ago

Your suggestion worked! I already have a simple poor man's SSR in my project: https://github.com/thelinuxlich/react-modern-starter

brillout commented 3 years ago

@thelinuxlich Note that starting with v3.2.2 you will not need to add it to ssr.noExternal.