Skip to content

Clerk fails to get the publishable key from the environment variables in Next.js 13 #1189

@Tsabary

Description

@Tsabary

I have a site I've built with Next 13 (experimental app directory) and have integrated authentication in my site with Clerk.

Everything works well on my local environment. When deployed to Netlify, it builds just fine, but if I try to visit the site it doesn't load, and in the console I see the following error:

@clerk/nextjs: Missing publishableKey. You can get your key at https://dashboard.clerk.com/last-active?path=api-keys.
    at Object.throwMissingPublishableKeyError

I do have my publishable key in my environment variables in Netlify under NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY. I've also placed it under CLERK_PUBLISHABLE_KEY just in case.

Also, does it supposed to get scoped automatically by some clerk code? Because in my code I don't really use that variable anywhere and don't see the documentation telling me I need to.

This is my publishable key environment variable:
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=pk_test_ZXZvbHZpbmctY29sdC01Ni5jbGVyay5hY2NvdW50cy5kZXYk

I'm building a Next app using the experimental app directory.

This is my package.json

{
    "name": "open-cards",
    "version": "0.1.0",
    "private": true,
    "scripts": {
        "dev": "next dev -p 3005",
        "build": "next build",
        "start": "next start",
        "lint": "next lint"
    },
    "dependencies": {
        "@clerk/nextjs": "^4.16.4",
        "@types/node": "18.15.13",
        "@types/react": "18.0.37",
        "@types/react-dom": "18.0.11",
        "autoprefixer": "10.4.14",
        "eslint": "8.38.0",
        "eslint-config-next": "13.3.0",
        "flowbite": "^1.6.5",
        "flowbite-react": "^0.4.4",
        "mongodb": "^5.3.0",
        "mongoose": "^7.0.4",
        "next": "^13.3.1-canary.4",
        "postcss": "8.4.23",
        "react": "18.2.0",
        "react-confetti": "^6.1.0",
        "react-dom": "18.2.0",
        "react-use": "^17.4.0",
        "socket.io-client": "^4.6.1",
        "tailwindcss": "3.3.1",
        "typescript": "5.0.4",
        "uuid": "^9.0.0",
        "webpack-node-externals": "^3.0.0"
    },
    "devDependencies": {
        "@types/uuid": "^9.0.1"
    }
}

Using windows and trying to run the site using Chrome/Brave

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions