antfu / nuxt-content-twoslash

TwoSlash integrations for Nuxt Content
MIT License
47 stars 6 forks source link

Error during module load when using @nuxtjs/mdc@0.8.2 #3

Open vernaillen opened 4 months ago

vernaillen commented 4 months ago

Describe the bug

When I added the nuxt-content-twoslash module to a new project generated from the github:nuxt-ui-pro/docs template, I encountered this error:

 ERROR  This module cannot be imported in server runtime. [importing @nuxt/kit from ../node_modules/.pnpm/@nuxtjs+mdc@0.8.2_rollup@3.29.4/node_modules/@nuxtjs/mdc/dist/config.mjs]                    8:07:31 AM

[8:07:31 AM]  ERROR  This module cannot be imported in server runtime. [importing ../node_modules/.pnpm/@nuxt+kit@3.12.2_rollup@3.29.4/node_modules/@nuxt/kit/dist/index.mjs from ../node_modules/.pnpm/@nuxtjs+mdc@0.8.2_rollup@3.29.4/node_modules/@nuxtjs/mdc/dist/module.mjs]

ℹ Vite client warmed up in 1282ms                                                                                                                                                                     8:07:31 AM
✔ Nitro built in 935 ms                                                                                                                                                                         nitro 8:07:31 AM

[8:07:32 AM]  ERROR  [worker reload] [worker init] The requested module 'file:///Users/wouter/git/wpnuxt/nuxt-content-twoslash/node_modules/.pnpm/unenv@1.9.0/node_modules/unenv/runtime/mock/proxy.cjs' does not provide an export named 'addComponent'

  import { defineNuxtModule, createResolver, addServerHandler, addComponent, addImports, addServerImports, addComponentsDir, hasNuxtModule, extendViteConfig, useNitro, addTemplate } from 'node_modules/.pnpm/unenv@1.9.0/node_modules/unenv/runtime/mock/proxy.cjs';
  ^^^^^^^^^^^^
  SyntaxError: The requested module 'node_modules/.pnpm/unenv@1.9.0/node_modules/unenv/runtime/mock/proxy.cjs' does not provide an export named 'addComponent'
  at ModuleJob._instantiate (node:internal/modules/esm/module_job:132:21)
  at async ModuleJob.run (node:internal/modules/esm/module_job:214:5)
  at async ModuleLoader.import (node:internal/modules/esm/loader:329:24)

I found out that the module still works with @nuxtjs/mdc@0.8.1, but breaks when using @nuxtjs/mdc@0.8.2.

For the reproduction I updated @nuxtjs/mdc to version 0.8.2 in the playground of the module repo, which triggers the error.

Reproduction

https://stackblitz.com/~/github.com/vernaillen/nuxt-content-twoslash

System Info

System:
    OS: macOS 14.5
    CPU: (14) arm64 Apple M3 Max
    Memory: 281.20 MB / 36.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 21.5.0 - ~/.nvm/versions/node/v21.5.0/bin/node
    Yarn: 1.22.21 - /opt/homebrew/bin/yarn
    npm: 10.2.4 - ~/.nvm/versions/node/v21.5.0/bin/npm
    pnpm: 8.15.3 - /usr/local/bin/pnpm
    bun: 1.0.18 - ~/.bun/bin/bun
  Browsers:
    Brave Browser: 120.1.61.101
    Chrome: 126.0.6478.127
    Safari: 17.5

Used Package Manager

pnpm

Validations

Contributions

vernaillen commented 4 months ago

The workaround for now is to fix the @nuxtjs/mdc version to 0.8.1 in package.json: "resolutions": { "@nuxtjs/mdc": "0.8.1" }

antfu commented 4 months ago

Fixed in https://github.com/nuxt-modules/mdc/pull/235, wait for the release