Implementing dynamic loading of Markdown files in Vue

I am exploring a way to load markdown files in my project.

<template>
  <HelloWorld />
</template>

<script setup>
import HelloWorld from './README.md'
</script>

My attempt involved using vite-plugin-md.

// 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$/], // <-- here
    }),
    markdown(),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url)),
    },
  },
})

However, I encountered an issue when running npm run dev:

error when starting dev server:
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined

    at new NodeError (node:internal/errors:400:5)
    at exportsNotFound (node:internal/modules/esm/resolve:361:10)
    at packageExportsResolve (node:internal/modules/esm/resolve:641: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)

Answer №1

I decided to test out the code you provided, and I must say it worked flawlessly: check it out here.

encountered error while running script:
Error [ERR_INVALID_INPUT]: Invalid input parameters

The error message ERR_INVALID_INPUT typically points to incorrect input parameters being passed. It's possible that something was missed during installation or setup.

To troubleshoot, consider removing the dependencies directory and re-running the npm install command.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What's the deal with Angular's factory pattern?

Is it possible to implement a true Factory pattern in JavaScript and Angular where there is no need to constantly provide the "typeName" parameter? The transition from C# to Java reference types with Angular has been quite challenging for me, and I would ...

Ways to instantly update state in the global environment

When I choose an item from my Select component dropdown, the id does not immediately change to reflect the newly selected item. It only updates when I re-select the same item. Below is a snippet of the relevant code: const EditBookingDetailsModal = () => ...

Utilizing a React object incorporating "$$typeof" with the Symbol(react.element), for the purpose of inserting CSS classes

I'm currently working on enhancing the calendar by dynamically adding a CSS class to each day. For reference, I'm using the Material-UI Pickers library, and the DatePicker API is quite helpful: It seems like the key to achieving this is through ...

Struggling to remove a row from the MUI DataGrid within a MERN CRUD application with Redux/RTK?

Struggling to understand why the delete button isn't working on my Material UI (MUI V5) Data Grid table. As a beginner in coding, especially with MERN and Redux, my mind is overwhelmed after trying various solutions all weekend - Google, Stack Overflo ...

Tips for preserving the status of radio buttons in a React application

I am currently utilizing a Map to keep track of the state of radio buttons, but I am facing challenges when it comes to correctly saving and updating it whenever a user makes a selection. The structure of my Map is as follows: { "Group A": [ ...

Using Javascript/NodeJS: Array becomes empty when values are pushed within a forEach loop

Experiencing a small hurdle here. Take a look at the code: Scenario A: var foundRiders = []; riders.forEach(function(rider){ Rider.findOne({_id: rider}, function(err, foundRider){ if(err){ ...

Update data automatically in AngularJS only when fresh data is retrieved from the server

I'm still learning AngularJS and I have a specific question regarding page refresh only when new data is fetched from the server. I've looked for solutions online, but haven't come across anything that fits my issue. Below is my Service an ...

Use JavaScript to transfer list values to a textbox area

<!doctype html> <html> <head> <meta charset="utf-8"/> <title>My Title</title> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> <s ...

Calculating the bounding box of an Object3D with BufferGeometry in Three.js using JavaScript

Having an Object3D with various levels of children (more Object3Ds or Meshes/Lines), I am trying to compute a bounding box of the object and all its descendants similar to the setFromObject() method in the Box3 class. Unfortunately, I can't utilize t ...

Issues with the initial calculator project I built using JavaScript (excluding HTML and CSS)

My first calculator is nearly complete, but I have encountered a challenge. The functionality of my calculator is quite simple; it prompts the user for input using window.prompt and performs addition, subtraction, multiplication, or division based on the u ...

Positioning social media icons directly below the Avatar component

I've been working on aligning my social media icons under the Avatar component. Despite trying multiple methods to center them in the JSS, I haven't had much success. I attempted different approaches but couldn't achieve the desired alignmen ...

Advantages of placing script src tags at the top of the body versus placing them at the bottom of the body

I've heard that it's best to place the script tags right before the closing body tag. However, when I follow this advice, my angularJS expressions don't seem to compute correctly for some reason. When I place the script tags in that location ...

Is there a way to access the initial element of the array within this variable assignment?

When utilizing the element id 10_food_select: var id = $(sel).attr("id").split("_"); An array is generated as follows: ["10", "food", "select"] The desired outcome is to have id = 10 (or whichever value is in the first element). This can be achieved l ...

When I make a post request, I receive a response in the form of an HTTPS link, but it is not redirected to

I'm making a post request and receiving the response as follows: " [Symbol(Response internals)]: {url: 'https://login.somenewloginpage'}" My intention is to open a new page using that URL, but unfortunately it does not redirect t ...

Encountered an issue following deployment to Heroku (Application error)

Introduction I recently created a Login form for my project. The frontend is deployed on Netlify at this link, and the backend is hosted on Heroku which can be accessed here. To view the backend logs, click here Here is a snippet of my index.js file: co ...

Iterate through several table data cells, extract various data points, and populate an array

I am facing a challenge with two tables on my webpage. The second table is dynamically populated with HTML using JavaScript. To accomplish this, I am checking if the <tr> tags inside the tbody are empty by using the following code: var rowCount = $( ...

How can I implement dynamic loading on a button click using Ajax?

Is it possible to create a loading button with a dynamic timer? Take a look at the code snippet below: var $this = $(this); $this.button('loading'); setTimeout(function() { $this.button('reset&apo ...

Why is my JavaScript sorting function not working after using push method?

Help me troubleshoot: Why aren't the results the same in IE9 and FF? function TestArrayOperationsClick() { function sortNums(a, b) { return a - b; } var array = [6, 4, 2, 8]; console.log("Initial Array: " + array); array.sort(sortNum ...

How to Delete Elements from an ngList Array in Angular

I encountered an issue while utilizing ngList in a text box to exchange data with my server. The problem arises when I attempt to delete items from the generated array directly, as it does not reflect the changes in the input field. The main concern is th ...

Unable to execute specific php function using ajax

I have created a script that utilizes an ajax request. This script is triggered when a user clicks a button on the index.php page, like so: Risorse.php <form method='post'> Name <input type='text' name='nome&apo ...