richie
March 14, 2023, 10:27am
1
My netlify site is: commonguide.netlify.app
I’ve run netlify env:import .env
per Get started with Netlify CLI | Netlify Docs , it takes a moment to run, but then seems to have done nothing (full log of debug output below) .
I’m running what I think is the latest version of netlify-cli (13.3.1) from my command line.
Locally I have a .env file that is ignored per .gitignore.
The project is linked to the correct repo, used netlify link
and double checked it too.
How I can tell it’s not working:
My deploy is still reporting the same error that implies that the environment variable is undefined.
Site Settings > Environment Variables remains empty
Running netlify env:list
reports “No environment variables set for site commonguide in the dev context”
Why is the contents of my .env file not uploading into the Environment Variables in the Netlify project?
Contents of .env
SITE_NAME=Common Guide
REPO_NAME=commonguide
REPO_URL=GitHub - CommonGuide/commonguide
EDIT_URI=edit/main/docs/
THEME_NAME=material
Log from running ‘netlify env:import .env --debug’:
branch: main
buildDir: /Users/me/projects/commonguide
configPath: /Users/me/projects/commonguide/netlify.toml
context: dev
env:
DEPLOY_ID
BUILD_ID
REPOSITORY_URL
NETLIFY_LOCAL
HEAD
COMMIT_REF
CACHED_COMMIT_REF
PULL_REQUEST
LANG
LANGUAGE
LC_ALL
GATSBY_TELEMETRY_DISABLED
NEXT_TELEMETRY_DISABLED
❯ Resolved config
build:
command: mkdocs build
commandOrigin: config
publish: /Users/me/projects/commonguide/site
publishOrigin: config
SamO
March 14, 2023, 2:53pm
2
Hi @richie ,
Are you running this in your root directory where the .env
is located? Were there any errors in the terminal output?
richie
March 14, 2023, 10:55pm
3
I’ve included the terminal output in the question.
Yeah no errors get reported, hence why initially I thought it was an error in how I was doing it.
richie
March 15, 2023, 12:36am
4
Yes i was running it in the root directory where the .env file is.
richie
March 15, 2023, 6:20am
5
I’ve worked out the issue.
My .env file included:
SITE_NAME=Common Guide
When I go to import this manually via the admin interface, it generates an error:
Sure enough, by removing an attempt to set SITE_NAME in my .env it then works.
Based on this, I’d now like to report a explicit bug.
Running netlify env:import .env
silently fails when a reserved environment variable
is included in the .env file.
To correct the bug:
The command should return an explicit fail and provide the same warning that is shown in the visual interfacet.
Something like this:
$ netlify env:import .env
Import failed. Reason: SITE_NAME is a reserved environment variable. Remove reserved variables from file and retry.
Please raise a ticket.
richie
March 16, 2023, 8:58am
6
Please raise a ticket.
Running netlify env:import .env
silently fails when a reserved environment variable
is included in the .env file.
To correct the bug:
The command should return an explicit fail and provide the same warning that is shown in the visual interface. Eg. Import failed. Reason: SITE_NAME is a reserved environment variable. Remove reserved variables from file and retry.
@richie thanks for the write up on it, it seems to be a bug indeed. Can you please open it on our public cli repo:
Thanks!
richie
March 17, 2023, 1:59am
8
Github issue raised as requested:
opened 01:57AM - 17 Mar 23 UTC
type: bug
Running env:import silently fails when .env includes reserved environment variab… les, in my case SITE_NAME.
I made a .env and ran $ netlify env:import .env
Despite multiple attempts I could not get the command to work, leading me down a garden path of attempted other fixes.
An explicit error message would turn a 2 hour random walk into a quick fix 🥺.
The command should return an explicit fail and provide the same warning that is shown in the visual interface.
Add an error message that is similar to what's in the web validation message, something like:
> env:import failed. Reason: SITE_NAME is a reserved environment variable. Remove reserved variables from file and retry.
Issue initially reported in the forums here: https://answers.netlify.com/t/netlify-env-import-env-not-uploading-environment-variables-into-the-linked-netlify-project/87695
### Steps to reproduce
How to reproduce:
1. Add a reserved environment variable to .env for example SITE_NAME=Example and VALID_VAR=Something
2. Run $ netlify import:env:import .env
3. Command will silently complete with no indication of success or failure, but it will have failed
4. Check $ netlify env:import and your variables will not have be added
5. Running the command with $ netlify import:env:import .env --debug provides not further insight, but the error should display whether debug is on or not.
### Configuration
My config:
```
### .env
SITE_NAME=Common Guide
REPO_NAME=commonguide
REPO_URL=[GitHub - CommonGuide/commonguide](https://github.com/CommonGuide/commonguide)
EDIT_URI=edit/main/docs/
THEME_NAME=material
```
```
### Log from running ‘netlify env:import .env --debug’:
branch: main
buildDir: /Users/me/projects/commonguide
configPath: /Users/me/projects/commonguide/netlify.toml
context: dev
env:
DEPLOY_ID
BUILD_ID
REPOSITORY_URL
NETLIFY_LOCAL
HEAD
COMMIT_REF
CACHED_COMMIT_REF
PULL_REQUEST
LANG
LANGUAGE
LC_ALL
GATSBY_TELEMETRY_DISABLED
NEXT_TELEMETRY_DISABLED
❯ Resolved config
build:
command: mkdocs build
commandOrigin: config
publish: /Users/me/projects/commonguide/site
publishOrigin: config
```
### Environment
System:
OS: macOS 11.7.4
CPU: (8) x64 Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz
Memory: 273.87 MB / 16.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 18.15.0 - ~/.asdf/installs/nodejs/18.15.0/bin/node
npm: 9.5.0 - ~/.asdf/plugins/nodejs/shims/npm
npmGlobalPackages:
netlify-cli: 13.1.3
SamO
March 17, 2023, 3:30pm
9
Thank you for raising this issue. I hope this is resolved soon.