3

I'm building my vue app also trying use this vite-plugin-md as my markdown loader.

/* vite.config.js */

import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { Markdown } from 'vite-plugin-md'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue({
      include: [/\.vue$/, /\.md$/], // <--
    }),
    Markdown(),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  }
})

But when I add the code provided in READMD.md and npm run dev. It comes errors below

failed to load config from /route/md-demo/vite.config.js
error when starting dev server:
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in /route/md-demo/node_modules/@yankeeinlondon/happy-wrapper/package.json
    at new NodeError (node:internal/errors:393:5)
    at exportsNotFound (node:internal/modules/esm/resolve:295:10)
    at packageExportsResolve (node:internal/modules/esm/resolve:575:13)
    at resolveExports (node:internal/modules/cjs/loader:538:36)
    at Module._findPath (node:internal/modules/cjs/loader:607:31)
    at Module._resolveFilename (node:internal/modules/cjs/loader:1025:27)
    at Module._load (node:internal/modules/cjs/loader:885:27)
    at Module.require (node:internal/modules/cjs/loader:1105:19)
    at require (node:internal/modules/cjs/helpers:103:18)
    at Object.<anonymous> (/route/md-demo/node_modules/vite-plugin-md/dist/index.cjs:18031:28)

I've tried use error keyword for searching related post and use npm update. Still won't work. Need help.

Late Update:

For anyone who hit the same issue. Add "type": "module" to the package.json to resolve this issue. Found in the discussion thread.

2
  • 2
    Yep same here, not sure why this is suddenly broken.
    – secondman
    Commented Dec 14, 2022 at 10:58
  • So it worked before?
    – Yang
    Commented Dec 14, 2022 at 12:12

2 Answers 2

1

I had the same problem and could resolve it by adding this key-value pair to my package.json file:

"module": true

Note that after applying this change, you may need to rename some of your files with .js extension to .cjs extension. Some examples are .eslintrc.js, .commitlintrc.js, .releaserc.js, postcss.config.js, and tailwind.config.js. But don't worry! Errors will guide you to identify which files need this change.

I guess you've migrated from an old version of Vite to a newer version, and by the old version I mean a version earlier than 3.x.x.

However, vite-plugin-md can't work with the old versions of Vite. Besides, Vite didn't put "module": true in package.json file in its old versions, but it does so in the newer versions. So, most of the people don't encounter this issue because they've already started their project with a fresh version of Vite.

1

The package is not vite-plugin-md. The right one is vite-plugin-vue-markdown.

The ERR_PACKAGE_PATH_NOT_EXPORTED always indicates a missing imported package.

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.