Getting error "Building the frontend app without an API key". Where does the .env file go?

Getting error "Building the frontend app without an API key". Where does the .env file go?

daveluke
Shopify Partner
25 2 9

I'm trying to create a web pixel app. When I run build, I get the following error:

 

Building the frontend app without an API key. The frontend build will not run without an API key. Set the SHOPIFY_API_KEY environment variable when running the build command.

 

I have a .env file in the root with SHOPIFY_API_KEY and SHOPIFY_API_SECRET.

 

Is this the wrong directory?

Replies 5 (5)

Patrick-Gephart
Shopify Partner
4 0 2

Hi @daveluke,

 

Are you using npm for development? If so, did you run "npm run shopify app env show" to see if it populated these in the correct root .env file for you?

I love to help companies reach their goals by building websites and applications that fit their needs and attract more customers.
daveluke
Shopify Partner
25 2 9

Thanks for the reply. I ran that command, and it output the correct values.

 

This is the error I get before the SHOPIFY_API_KEY error however:

 

file: /Users/.../.../web/frontend/node_modules/@shopify/polaris/build/esm/styles.css

frontend               │ error during build:

frontend               │ TypeError: Cannot read properties of undefined (reading 'config')

 

Update: it has something to do with the frontend and Vite. I am just trying to add a web pixel extensions to an existing app, so I am not interested in building the Shopify CLI generated web app. After I fixed that error, the .env error went away. Thanks.

Patrick-Gephart
Shopify Partner
4 0 2

@daveluke glad you figured it out.

I love to help companies reach their goals by building websites and applications that fit their needs and attract more customers.
derenhg
Shopify Partner
14 0 2

I am facing similar error when building with docker file in server any idea how to resolve?

jonaswebdev
Shopify Partner
6 0 0

Hi, try to set the API Key on the system variables environment before "build", something like this:

export SHOPIFY_API_KEY="YOUR KEY HERE"
npm run build

 

if it still doesn't work, try to put all on the same command, like this:

export SHOPIFY_API_KEY="YOUR KEY HERE" && npm run build

 

This second way worked for me 🙂