3

使用 @nuxtjs/prismic 和 nuxt-i18n 时收到错误消息。

错误信息 :

错误 ENOENT:没有这样的文件或目录,打开 'C:\wamp64\www\nuxt-test\prismic\.nuxt\prismic\pages\preview.vue

包.json

{
  "name": "prismic-nuxtjs",
  "version": "1.0.0",
  "scripts": {
    "dev": "nuxt",
    "build": "nuxt build",
    "start": "nuxt start",
    "generate": "nuxt generate",
    "lint": "eslint --ext .js,.vue --ignore-path .gitignore ."
  },
  "dependencies": {
    "@nuxtjs/axios": "^5.3.6",
    "@nuxtjs/dotenv": "^1.4.0",
    "@nuxtjs/prismic": "^1.0.1",
    "@nuxtjs/pwa": "^3.0.0-0",
    "nuxt": "^2.0.0",
    "nuxt-i18n": "^6.5.0"
  },
  "devDependencies": {
    "@nuxtjs/tailwindcss": "^1.0.0",
    "@nuxtjs/eslint-config": "^1.0.1",
    "@nuxtjs/eslint-module": "^1.0.0",
    "babel-eslint": "^10.0.1",
    "eslint": "^6.1.0",
    "eslint-plugin-nuxt": ">=0.4.2",
    "@nuxtjs/stylelint-module": "^3.1.0",
    "stylelint": "^10.1.0",
    "stylelint-config-recommended": "^3.0.0"
  }
}

nuxt.config.js

export default {
  mode: 'universal',
  /*
  ** Headers of the page
  */
  head: {
    title: process.env.npm_package_name || '',
    meta: [
      { charset: 'utf-8' },
      { name: 'viewport', content: 'width=device-width, initial-scale=1' },
      { hid: 'description', name: 'description', content: process.env.npm_package_description || '' }
    ],
    link: [
      { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }
    ]
  },
  /*
  ** Customize the progress-bar color
  */
  loading: { color: '#fff' },
  /*
  ** Global CSS
  */
  css: [
  ],
  /*
  ** Plugins to load before mounting the App
  */
  plugins: [
  ],
  /*
  ** Nuxt.js dev-modules
  */
  buildModules: [
    // Doc: https://github.com/nuxt-community/eslint-module
    '@nuxtjs/eslint-module',
    // Doc: https://github.com/nuxt-community/stylelint-module
    '@nuxtjs/stylelint-module',
    // Doc: https://github.com/nuxt-community/nuxt-tailwindcss
    '@nuxtjs/tailwindcss'
  ],
  /*
  ** Nuxt.js modules
  */
  modules: [
    // Doc: https://axios.nuxtjs.org/usage
    '@nuxtjs/axios',
    '@nuxtjs/pwa',
    // Doc: https://github.com/nuxt-community/dotenv-module
    '@nuxtjs/dotenv',
    // Doc : https://prismic-nuxt.js.org
    '@nuxtjs/prismic',
    // Doc : https://nuxt-community.github.io/nuxt-i18n/
    ['nuxt-i18n', {
      lazy: true,
      locales: [
        {
          name: 'French',
          code: 'fr',
          iso: 'fr-FR',
          file: 'fr-FR.js'
        },
        {
          name: 'English',
          code: 'en',
          iso: 'en-US',
          file: 'en-US.js'
        },
      ],
      langDir: 'lang/',
      defaultLocale: 'fr'
    }]
  ],

  /*
  ** Prismic configuration
  */
  prismic: {
    endpoint: 'https://nuxt-prismic-20.cdn.prismic.io/api/v2'
  },

  /*
  ** Axios module configuration
  ** See https://axios.nuxtjs.org/options
  */
  axios: {
  },
  /*
  ** Build configuration
  */
  build: {
    /*
    ** You can extend webpack config here
    */
    extend (config, ctx) {
    }
  }
}

在根目录下,我有一个/lang包含两个文件的文件夹: /fr-FR.js/en-US.js

为了尝试解决这个问题,我创建了一个预览文件app/prismic/pages/preview.vue 但是我得到了同样的信息: ERROR ENOENT: no such file or directory, open 'C:\wamp64\www\nuxt-test\prismic\.nuxt\prismic\pages\预览.vue

任何想法为什么?

谢谢你,亚历克斯。

4

1 回答 1

3

在您的 i18n 部分中nuxt.config.js,设置parsePages为 false。

例子:

i18n: {
    locales: ["nl", "en"],
    defaultLocale: "nl",
    vueI18n: {
      fallbackLocale: "nl",
      messages: locales
    },
    parsePages: false
  },

文档中:

// By default, custom routes are extracted from page files using babel parser,
// set this to false to disable this
parsePages: true,
于 2020-03-30T11:26:12.483 回答