Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SESSION_SECRET is not defined in fresh development setup #129

Open
ccjmne opened this issue Oct 19, 2022 · 10 comments
Open

SESSION_SECRET is not defined in fresh development setup #129

ccjmne opened this issue Oct 19, 2022 · 10 comments

Comments

@ccjmne
Copy link

ccjmne commented Oct 19, 2022

Hello @ericallam 👋

I wanted to take a look at this and started playing with the project, but couldn't get it set up...
I didn't want to open an issue simply for this; but maybe you can just point me in the right direction without much trouble 🙇‍♀️

I basically simply followed the procedure indicated in DEVELOPMENT.md, created my .env file:
image

I could run all the tests, perform npm run dev, it all works fine... until npm start:

[1] [mf:err] C:\Users\Patricia\git\jsonhero-web\dist\worker.js:54468
[1]   var sessionSecret = SESSION_SECRET;
[1]                       ^
[1]
[1] ReferenceError: SESSION_SECRET is not defined
[1]     at C:\Users\Patricia\git\jsonhero-web\app\theme.server.ts:5:23
[1]     at C:\Users\Patricia\git\jsonhero-web\dist\worker.js:106223:3
[1]     at Script.runInContext (node:vm:139:12)
[1]     at VMScriptRunner.runAsScript (C:\Users\Patricia\git\jsonhero-web\node_modules\@miniflare\runner-vm\src\index.ts:25:12)
[1]     at VMScriptRunner.run (C:\Users\Patricia\git\jsonhero-web\node_modules\@miniflare\runner-vm\src\index.ts:84:12)
[1]     at EventTarget.#reload (C:\Users\Patricia\git\jsonhero-web\node_modules\@miniflare\core\src\index.ts:775:42)
[1]     at EventTarget.getPlugins (C:\Users\Patricia\git\jsonhero-web\node_modules\@miniflare\core\src\index.ts:1017:5)
[1]     at createServer (C:\Users\Patricia\git\jsonhero-web\node_modules\@miniflare\http-server\src\index.ts:369:19)
[1]     at startServer (C:\Users\Patricia\git\jsonhero-web\node_modules\@miniflare\http-server\src\index.ts:476:18)
[1]     at main (C:\Users\Patricia\git\jsonhero-web\node_modules\miniflare\src\cli.ts:111:7)
[1] [mf:err] Unhandled Promise Rejection: C:\Users\Patricia\git\jsonhero-web\dist\worker.js:54468
[1]   var sessionSecret = SESSION_SECRET;
[1]                       ^

Why isn't it picking up my .env file? What am I doing wrong?

OS: Windows 10

@ericallam
Copy link
Member

Could you try running npm run build and then try npm start?

@ccjmne
Copy link
Author

ccjmne commented Oct 19, 2022

Thanks for the immediate response!
There's no difference however...

PS C:\Users\Patricia\git\jsonhero-web> npm run build

> build
> npm run build:css && npm run build:search && remix build


> build:css
> tailwindcss -i ./styles/tailwind.css -o ./app/tailwind.css --minify

Browserslist: caniuse-lite is outdated. Please run:
  npx browserslist@latest --update-db
  Why you should do it regularly: https://github.com/browserslist/browserslist#browsers-data-updating
Browserslist: caniuse-lite is outdated. Please run:
  npx browserslist@latest --update-db

warn - The `@variants` directive has been deprecated in Tailwind CSS v3.0.
warn - Use `@layer utilities` or `@layer components` instead.
warn - https://tailwindcss.com/docs/upgrade-guide#replace-variants-with-layer

Done in 1238ms.

> build:search
> esbuild ./app/entry.worker.ts --outfile=./public/entry.worker.js --bundle --format=esm --define:process.env.NODE_ENV='"production"'


  public\entry.worker.js  649.1kb

Done in 55ms
Building Remix app in production mode...
Built in 1.5s
PS C:\Users\Patricia\git\jsonhero-web> npm start

> start
> concurrently "npm run dev" "npm run start:worker"

[0] 
[0] > dev
[0] > concurrently "npm run dev:css" "npm run dev:search" "remix watch"
[0]
[1]
[1] > start:worker
[1] > miniflare --env .env --build-command "npm run dev:worker" --watch
[1]
[1] (node:4160) ExperimentalWarning: stream/web is an experimental feature. This feature could change at any time
[1] (Use `node --trace-warnings ...` to show where the warning was created)
[0] [2] Watching Remix app in development mode...
[0] [0] 
[0] [0] > dev:css
[0] [0] > tailwindcss -i ./styles/tailwind.css -o ./app/tailwind.css --watch
[0] [0]
[0] [1] 
[0] [1] > dev:search
[0] [1] > esbuild ./app/entry.worker.ts --outfile=./public/entry.worker.js --bundle --format=esm --define:process.env.NODE_ENV='"development"' --watch
[0] [1]
[1] 
[1] > dev:worker
[1] > esbuild --define:process.env.NODE_ENV='"development"' --bundle --sourcemap --outdir=dist ./worker
[1]
[0] [1] [watch] build finished, watching for changes...
[1] 
  dist\worker.js      2.3mb
[1]   dist\worker.js.map  3.4mb
[1]
[1] Done in 559ms
[1] [mf:inf] Build succeeded
[0] [2] 💿 Built in 2.5s
[0] [0] Browserslist: caniuse-lite is outdated. Please run:
[0] [0]   npx browserslist@latest --update-db
[0] [0]   Why you should do it regularly: https://github.com/browserslist/browserslist#browsers-data-updating
[0] [0] 
[0] [0] warn - The `@variants` directive has been deprecated in Tailwind CSS v3.0.
[0] [0] warn - Use `@layer utilities` or `@layer components` instead.
[0] [0] warn - https://tailwindcss.com/docs/upgrade-guide#replace-variants-with-layer
[0] [0]
[0] [0] Rebuilding...
[1] [mf:err] C:\Users\Patricia\git\jsonhero-web\dist\worker.js:23923
[1]   var Lwe = SESSION_SECRET;
[1]             ^
[1]
[1] ReferenceError: SESSION_SECRET is not defined
[1]     at C:\Users\Patricia\git\jsonhero-web\build\index.js:67:317
[1]     at C:\Users\Patricia\git\jsonhero-web\dist\worker.js:52767:3
[1]     at Script.runInContext (node:vm:139:12)
[1]     at VMScriptRunner.runAsScript (C:\Users\Patricia\git\jsonhero-web\node_modules\@miniflare\runner-vm\src\index.ts:25:12)
[1]     at VMScriptRunner.run (C:\Users\Patricia\git\jsonhero-web\node_modules\@miniflare\runner-vm\src\index.ts:84:12)  
[1]     at EventTarget.#reload (C:\Users\Patricia\git\jsonhero-web\node_modules\@miniflare\core\src\index.ts:775:42)     
[1]     at EventTarget.getPlugins (C:\Users\Patricia\git\jsonhero-web\node_modules\@miniflare\core\src\index.ts:1017:5)  
[1]     at createServer (C:\Users\Patricia\git\jsonhero-web\node_modules\@miniflare\http-server\src\index.ts:369:19)     
[1]     at startServer (C:\Users\Patricia\git\jsonhero-web\node_modules\@miniflare\http-server\src\index.ts:476:18)      
[1]     at main (C:\Users\Patricia\git\jsonhero-web\node_modules\miniflare\src\cli.ts:111:7)
[1] [mf:err] Unhandled Promise Rejection: C:\Users\Patricia\git\jsonhero-web\dist\worker.js:23923
[1]   var Lwe = SESSION_SECRET;
[1]             ^
[1]
[1] ReferenceError: SESSION_SECRET is not defined
[1]     at C:\Users\Patricia\git\jsonhero-web\build\index.js:67:317
[1]     at C:\Users\Patricia\git\jsonhero-web\dist\worker.js:52767:3
[1]     at Script.runInContext (node:vm:139:12)
[1]     at VMScriptRunner.runAsScript (C:\Users\Patricia\git\jsonhero-web\node_modules\@miniflare\runner-vm\src\index.ts:25:12)
[1]     at VMScriptRunner.run (C:\Users\Patricia\git\jsonhero-web\node_modules\@miniflare\runner-vm\src\index.ts:84:12)  
[1]     at EventTarget.#reload (C:\Users\Patricia\git\jsonhero-web\node_modules\@miniflare\core\src\index.ts:775:42)     
[1]     at EventTarget.getPlugins (C:\Users\Patricia\git\jsonhero-web\node_modules\@miniflare\core\src\index.ts:1017:5)  
[1]     at createServer (C:\Users\Patricia\git\jsonhero-web\node_modules\@miniflare\http-server\src\index.ts:369:19)     
[1]     at startServer (C:\Users\Patricia\git\jsonhero-web\node_modules\@miniflare\http-server\src\index.ts:476:18)      
[1]     at main (C:\Users\Patricia\git\jsonhero-web\node_modules\miniflare\src\cli.ts:111:7)
[1] npm run start:worker exited with code 1
[0] [0] Done in 868ms.
[0] [2] 💿 File changed: app\tailwind.css
[0] [2] 💿 Rebuilding...
[0] [2] 💿 Rebuilt in 1s

@ccjmne
Copy link
Author

ccjmne commented Oct 19, 2022

NB: .env does contain a proper SESSION_SECRET and isn't empty:

SESSION_SECRET=54c75f2dad5520a2b7f5168fbdfa6a5c410827bb6cb9c33e8ff291a7bd0d3d88

@ericallam
Copy link
Member

Interesting... so npm run dev works, what does npm run start:worker do if you run it separately?

@ccjmne
Copy link
Author

ccjmne commented Oct 19, 2022

Just the same :(
At least it's consistent!

PS C:\Users\Patricia\git\jsonhero-web> npm run start:worker

> start:worker
> miniflare --env .env --build-command "npm run dev:worker" --watch

(node:13352) ExperimentalWarning: stream/web is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)

> dev:worker
> esbuild --define:process.env.NODE_ENV='"development"' --bundle --sourcemap --outdir=dist ./worker


  dist\worker.js      4.2mb
  dist\worker.js.map  7.4mb

Done in 687ms
[mf:inf] Build succeeded
[mf:err] C:\Users\Patricia\git\jsonhero-web\dist\worker.js:54468
  var sessionSecret = SESSION_SECRET;
                      ^

ReferenceError: SESSION_SECRET is not defined
    at C:\Users\Patricia\git\jsonhero-web\app\theme.server.ts:5:23
    at C:\Users\Patricia\git\jsonhero-web\dist\worker.js:106223:3
    at Script.runInContext (node:vm:139:12)
    at VMScriptRunner.runAsScript (C:\Users\Patricia\git\jsonhero-web\node_modules\@miniflare\runner-vm\src\index.ts:25:12)
    at VMScriptRunner.run (C:\Users\Patricia\git\jsonhero-web\node_modules\@miniflare\runner-vm\src\index.ts:84:12)      
    at EventTarget.#reload (C:\Users\Patricia\git\jsonhero-web\node_modules\@miniflare\core\src\index.ts:775:42)
    at EventTarget.getPlugins (C:\Users\Patricia\git\jsonhero-web\node_modules\@miniflare\core\src\index.ts:1017:5)      
    at createServer (C:\Users\Patricia\git\jsonhero-web\node_modules\@miniflare\http-server\src\index.ts:369:19)
    at startServer (C:\Users\Patricia\git\jsonhero-web\node_modules\@miniflare\http-server\src\index.ts:476:18)
    at main (C:\Users\Patricia\git\jsonhero-web\node_modules\miniflare\src\cli.ts:111:7)
[mf:err] Unhandled Promise Rejection: C:\Users\Patricia\git\jsonhero-web\dist\worker.js:54468
  var sessionSecret = SESSION_SECRET;
                      ^

ReferenceError: SESSION_SECRET is not defined
    at C:\Users\Patricia\git\jsonhero-web\app\theme.server.ts:5:23
    at C:\Users\Patricia\git\jsonhero-web\dist\worker.js:106223:3
    at Script.runInContext (node:vm:139:12)
    at VMScriptRunner.runAsScript (C:\Users\Patricia\git\jsonhero-web\node_modules\@miniflare\runner-vm\src\index.ts:25:12)
    at VMScriptRunner.run (C:\Users\Patricia\git\jsonhero-web\node_modules\@miniflare\runner-vm\src\index.ts:84:12)      
    at EventTarget.#reload (C:\Users\Patricia\git\jsonhero-web\node_modules\@miniflare\core\src\index.ts:775:42)
    at EventTarget.getPlugins (C:\Users\Patricia\git\jsonhero-web\node_modules\@miniflare\core\src\index.ts:1017:5)      
    at createServer (C:\Users\Patricia\git\jsonhero-web\node_modules\@miniflare\http-server\src\index.ts:369:19)
    at startServer (C:\Users\Patricia\git\jsonhero-web\node_modules\@miniflare\http-server\src\index.ts:476:18)
    at main (C:\Users\Patricia\git\jsonhero-web\node_modules\miniflare\src\cli.ts:111:7)

@ericallam
Copy link
Member

Just curious, which version of node are you on?

@ccjmne
Copy link
Author

ccjmne commented Oct 19, 2022

My current Node version is v16.13.0

@ccjmne
Copy link
Author

ccjmne commented Oct 19, 2022

It does pick up the .env file, as well; because when I try to delete/move/rename it, it errors out with:

[1] [mf:inf] Build succeeded
[1] [mf:err] Error: ENOENT: no such file or directory, open 'C:\Users\Patricia\git\jsonhero-web\.env'
[1] Error: ENOENT: no such file or directory, open 'C:\Users\Patricia\git\jsonhero-web\.env'
[1] npm run start:worker exited with code 1

@ericallam
Copy link
Member

I wonder if miniflare isn't correctly passing the env vars through to the subcommand npm run dev:worker. Digging into miniflare now...

@ccjmne
Copy link
Author

ccjmne commented Oct 24, 2022

Hey @ericallam, 👋
I figured I'd give it another go and try looking into what's going on... but I can't seem to figure it out.
If you've got any findings, please let me know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants