I connected my react app with Contentful's database. When I give the access key directly, it works fine. But when I give an access key in .env.environment file, the variable does not work.
contentful.js file:
import {createClient} from 'contentful';
export default createClient({
space: process.env.REACT_APP_API_SPACE,
accessToken: process.env.REACT_APP_ACCESS_TOKEN
});
.env.enviroment file:
REACT_APP_API_SPACE= my access key
REACT_APP_ACCESS_TOKEN= my access token
Console error:
Uncaught TypeError: Expected parameter accessToken
at createClient (contentful.node.js:7563)
at Object.<anonymous> (Contentful.js:3)
at __webpack_require__ (bootstrap fafcbb2b670a4f50dfbb:555)
at fn (bootstrap fafcbb2b670a4f50dfbb:86)
at Object.<anonymous> (context.js:5)
at __webpack_require__ (bootstrap fafcbb2b670a4f50dfbb:555)
at fn (bootstrap fafcbb2b670a4f50dfbb:86)
at Object.<anonymous> (FeaturedRooms.js:2)
at __webpack_require__ (bootstrap fafcbb2b670a4f50dfbb:555)
at fn (bootstrap fafcbb2b670a4f50dfbb:86)
But it works fine when I give the access key directly in my contentful.js file like this:
import {createClient} from 'contentful';
export default createClient({
space: my access key,
accessToken: my access token
});
As I am uploading to Git, I don't want to give the key directly.
.envnot.env.environmentnpm run startcommand.