npm - @nuxt/content 页面在生产模式下找不到

标签 npm markdown nuxt.js

说明

您好,当我运行 npm run build && npm run start 时,我的项目中出现了 nuxt/content 问题。 你要知道,在开发模式下是没有问题的。

当我运行生产模式时,我无法访问与 nuxt/content 一起使用的文件,您可以看到出现在我的控制台中的错误。

Picture : Problem which appear in my console in production mode

编辑

我发现问题出在哪里,这个错误来自 SPA(如果我选择 SSR,它可以正常工作)。有人有解决办法吗?

重现问题的步骤:

  1. 创建一个项目:npx create-nuxt-app content-project && cd content-project 下面是我的配置。 Picture : Configuration of my project
  2. 进入项目然后安装 nuxt/content : npm install @nuxt/content
  3. 进入 nuxt.config.js 并添加到 "modules: []"this : '@nuxt/content' 然后添加 "content: {}"
    Picture : Adding lines to nuxt.config.js
  4. 在 tsconfig.json 中,在“types”处添加以下行:“@nuxt/content”,
    Picture : Adding line to tsconfig.json
  5. 在项目的根目录中,添加一个名为“content”的目录,在此目录中创建一个名为“test.md”的文件,并将以下行添加到文件中:
---
title: Introduction
description: Apprenez comment utiliser @nuxt/content.
---

## Liens

<nuxt-link to="/articles">Nuxt Link vers le Blog</nuxt-link>

<a href="/articles">Lien Html vers le Blog</a>

[Lien Markdown vers le Blog](/fr/articles)

<a href="https://nuxtjs.org">Lien Html externe</a>

[Lien Markdown externe](https://nuxtjs.org)
  1. 进入 pages 目录,创建一个名为“testcontent.vue”的新文件并将此代码添加到:
<template>
  <article>
    <h1>{{ page.title }}</h1>
    <nuxt-content :document="page" />
  </article>
</template>

<script>
export default {
  async asyncData({ $content }) {
    const page = await $content('test').fetch()

    return {
      page,
    }
  },
}
</script>
  1. 现在,您可以保存并在开发模式下尝试此操作 npm run dev,尝试此链接“http://localhost:3000/testcontent”,这应该有效。
  2. 然后在生产模式下尝试此操作 npm run build && npm run start。我不明白为什么那行不通。

最佳答案

您完全可以使用 SPA,甚至是带有 target: static 的完整通用应用程序。我不确定您的答案中的链接帖子是否正确。

它清楚地表明您可以获得 target: static(因此,将其托管在 Netlify 或类似的平台上)并保持通用模式(ssr: true(默认)) , 作为 shown in the documentation .唯一需要做的是 nuxt generate 而不是 nuxt build,因为您的目标是静态构建。

另外,这条评论已有 6 个月以上了,我们从今天开始使用 Nuxt 2.15.2。

我仍然建议使用 static + universal 以获得 nuxt + 它的内容模块的所有好处。

关于npm - @nuxt/content 页面在生产模式下找不到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66442714/

相关文章:

node.js - 通过 Bower 安装软件包

node.js - 一个 GitHub 存储库中具有范围界定的多个 NPM 存储库?

javascript - Nuxt.js 和 Vue-i18next : Error: Cannot resolve "vue-i18next"

node.js - Nuxt js错误找不到页面目录

node.js - npm 包在 MeteorJS 应用程序中无法按预期工作

node.js - 安装 Nodejs v9.0.0 后如何将 npm 从 v5.4.1 升级到最新版本

python - 使用 python-markdown 检查图像 url

python - 在FastAPI自动文档中插入本 map 片

Python markdown 添加类到表格

javascript - 在 Firebase 上托管 Nuxt.js SSR 应用程序时出现问题