Giter VIP home page Giter VIP logo

Comments (4)

thiagorossener avatar thiagorossener commented on June 13, 2024 1

@y-takebe thank you very much for your help!

I tried what you said, but it works only in production, it stops working in development.

So, I had to change some things to make it work in both environments.

In nuxt.config.js:

import { defineNuxtConfig } from "nuxt";

// https://v3.nuxtjs.org/docs/directory-structure/nuxt.config
export default defineNuxtConfig({
  runtimeConfig: {
    dev: process.env.NODE_ENV !== "production",
  },
});

Then, in contentful.js:

import * as contentful from "contentful";

export default defineNuxtPlugin((nuxtApp) => {
  const config = useRuntimeConfig();
  // Workaround to make the build work on development AND production
  const createClient = config.dev ? contentful.createClient : contentful.default.createClient;
  const client = createClient({
    space: config.ctfSpaceId,
    accessToken: config.ctfCdaAccessToken,
  });
  nuxtApp.provide("contentfulClient", client);
});

Hope it can help you too.

from tech-blog-vue3-nuxt3.

y-takebe avatar y-takebe commented on June 13, 2024

Hi @thiagorossener, thanks wrote a comment.

But I’m Sorry, I trying local development now, I haven't gone that SSR and/or SSG deployment yet. In my plan, it will be a few days later.

When I was use a beta version, wrote this syntax was work.

import contentful from "contentful”;

However, When I was update to a RC version after, same happen to me.

TypeError: contentful.createClient is not a function

So, I try changed import * as … syntax and trouble was fix.

I use the latest version.

  • contentful: 9.1.24
  • nuxt: 3.0.0-rc.1

from tech-blog-vue3-nuxt3.

thiagorossener avatar thiagorossener commented on June 13, 2024

Thanks for the response @y-takebe.

I've updated my project to use [email protected] and [email protected], but I keep getting:

[nuxt] [request error] contentful.createClient is not a function

It works fine on development, but when trying SSR or SSG this happens.

I'm importing contentful like:

import * as contentful from "contentful";

Does your page work perfectly when running npm run build, then npm run start? I get an error 500 when I do that.

from tech-blog-vue3-nuxt3.

y-takebe avatar y-takebe commented on June 13, 2024

@thiagorossener

I tried.

In this case,

import * as contentful from "contentful";

Response is 500 error. But, this case:

import contentful from "contentful";

and nuxt.config.ts is:

  target: 'server',

I have few minor problem, but working.

Hope this helps a little!

from tech-blog-vue3-nuxt3.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.