Comments (4)
@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.
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.
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.
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)
- Development server fails to start HOT 2
- Can't access sub pages after yarn generated HOT 1
- Static image is not visible with static mode (ssg) HOT 1
- Article section generated by contentful is hidden on the Production environment HOT 1
- Determine the license
- Implement initial features
- Load tags from contentful
- add style lint
- add lint reviewdog on github actions
- optimize of large size images
- Repair breaking mobile layout
- Implement v0.2.0 features
- Set OGP properties
- tune-up for Lighthouse
- Lighthouse perfect score
- Category is broken
- API Keys HOT 15
- Broken layout if use code block in markdown (only mobile) HOT 1
- Upgrade to Nuxt 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tech-blog-vue3-nuxt3.