question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

prepare script does not read env_variables

See original GitHub issue

Hi all,

I’m not sure this issue is ONTOPIC, I just use some code from your example.

I have some issue to get the process.env from a prepare script in package.json. I’m trying to run mysql migration before starting the app but I can not fetch the process.env variables

My package.json

...
  "scripts": {
     ...
    "prepare": "npm run gcp-build",
    "gcp-build": "node migrations.js",
  },
...

My migrations.js

var path = require('path')
var mysql = require('mysql')
var migration = require('mysql-migrations')

require('dotenv').config()

var connection = mysql.createPool({
  connectionLimit: 10,
  host: process.env.DB_HOST,
  user: process.env.DB_USER,
  password: process.env.DB_PASS,
  database: process.env.DB_NAME
})

migration.init(connection, path.join(__dirname, '/migrations'))

My app read the env_variables from app.yaml without problem but the prepare script do not.

Any help will be appreciated.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
fhinkelcommented, Oct 3, 2019

That’s almost the same reproduction that I used 😄

Glad you found a solution. I opened a bug internally to clarify that in our docs, so other people don’t run in to the same problem. Thanks again for reporting!

0reactions
ahmadnassricommented, Feb 4, 2021

I finally got my full deploy workflow working and gcp-build was failing to run db migration … then I found this issue …

TABLE FLIP!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to set environment variables from within package.json?
The NODE_ENV environment variable will be set by cross-env ... Then, in your package json, you will create a script that will set...
Read more >
How To Use .env Variables In package.json - GenUI
The Problem. It's common to need access to your environment variables in multiple places. Your code, your build scripts, and your pipeline may...
Read more >
How to use environment variables in NPM scripts safely ... - SwC
A blog post on the topic of: How to use environment variables in NPM scripts safely across operating systems.
Read more >
Environment Variable Configuration on the Official Guides Not ...
I have worked on a project on macos for a while and started it up on a windows machine today and had this...
Read more >
BASH script to set environment variables not working
When you run a script, it runs in a subshell. Variables are only valid within the context of that subshell. Set them in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found