wobsoriano/unplugin-markdoc

Dynamic require of "path" is not supported.

Closed this issue · 5 comments

I created a project using vite's react-ts template and am going to use Markdoc.

I followed the README of markdoc and unplugin-markdoc and let me share details of configs.

vite.config.js

import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import MarkdocPlugin from "unplugin-markdoc/vite";
import path from "path";

// https://vitejs.dev/config/
export default defineConfig({
	plugins: [react(), MarkdocPlugin()],
	resolve: {
		alias: {
			"@": path.resolve(__dirname, "./src"),
			"@containers": path.resolve(__dirname, "./src/containers"),
			"@pages": path.resolve(__dirname, "./src/pages"),
		},
	},
});

Home.tsx

import { Document } from "@containers";

export function Home() {
	return (
		<div>
			<Document
				source={`
					# Hello world.
					> My first Markdoc page
				`}
			/>
		</div>
	);
}

export default Home;

Document.tsx

import React from "react";
import Markdoc from "@markdoc/markdoc";

const config = {};

interface DocumentProps {
	source: string;
}

export function Document({ source }: DocumentProps) {
	const ast = Markdoc.parse(source);
	const content = Markdoc.transform(ast, config);

	return Markdoc.renderers.react(content, React);
}

export default Document;

And ran yarn dev but seeing the below error.

$ yarn dev
yarn run v1.22.19
$ vite
failed to load config from C:\repos\docs\vite.config.ts
error when starting dev server:
Error: Dynamic require of "path" is not supported
    at file:///C:/repos/docs/node_modules/unplugin-markdoc/dist/chunk-HWMXROXT.js:29:9
    at node_modules/.pnpm/picomatch@2.3.1/node_modules/picomatch/lib/picomatch.js (file:///C:/repos/docs/node_modules/unplugin-markdoc/dist/chunk-HWMXROXT.js:1355:16)
    at __require2 (file:///C:/repos/docs/node_modules/unplugin-markdoc/dist/chunk-HWMXROXT.js:32:50)
    at node_modules/.pnpm/picomatch@2.3.1/node_modules/picomatch/index.js (file:///C:/repos/docs/node_modules/unplugin-markdoc/dist/chunk-HWMXROXT.js:1499:22)        
    at __require2 (file:///C:/repos/docs/node_modules/unplugin-markdoc/dist/chunk-HWMXROXT.js:32:50)
    at file:///C:/repos/docs/node_modules/unplugin-markdoc/dist/chunk-HWMXROXT.js:1507:32
    at ModuleJob.run (node:internal/modules/esm/module_job:194:25)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Released a new version. Can you try 0.3.1?

@wobsoriano it doesn't show an error but still not showing the correct markdown.

Would you be able to make a basic reproduction?

Did you make it work?

Yes. unplugin-markdoc issue was addressed in v0.3.1