0

I have installed chromatic to my project and I wanted to add a command to npm scripts for it with following setting in package.json.

 "scripts": {
    ...
    "chromatic": "chromatic --project-token=$CHROMATIC_PROJECT_TOKEN",
  },

Since the CHROMATIC_PROJECT_TOKEN is secret token, I decided to define an environment variable in .env.local along the rule of Next.js.

Note: similar to Default Environment Variables, .env.test file should be included in your repository, but .env.test.local shouldn't, as .env*.local are intended to be ignored through .gitignore.

# chromatic token
CHROMATIC_PROJECT_TOKEN=1234567890

And I run a following command after executing $ next dev,

$ yarn chromatic

and this error occured.

enter image description here

I reseached in github seeing other's code using chromatic and they seemed ended up hardcoding the token to the npm scripts. Does anyone can tell me how to let npm scripts read the environment variables defined in .env.local?

pop
  • 69
  • 1
  • 1
  • 8
  • Where are you using this `project-token` in the code? You could access the env variable in your code, instead of passing it to npm script. – Youssouf Oumar Mar 09 '23 at 09:49
  • well, the `project-token` is only used in this npm script. and yes, I know that I can use the env variable in my CSR code with `NEXT_PUBLIC` prefix. – pop Mar 09 '23 at 14:48

0 Answers0