serverless-next.js
serverless-next.js copied to clipboard
SyntaxError: Invalid left-hand side in assignment
Describe the bug
Looks like the tool doesn't play nice when you have an .env variable in the same folder you run serverless
. I understand there's a way of passing environment variables to the script but for people coming in trying to deploy their existing apps that already use this form of passing parameters might have a bad experience with the tool.
Actual behavior
It crashes with:
SyntaxError: Invalid left-hand side in assignment
at wrapSafe (internal/modules/cjs/loader.js:1116:16)
at Module._compile (internal/modules/cjs/loader.js:1164:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1220:10)
at Module.load (internal/modules/cjs/loader.js:1049:32)
at Function.Module._load (internal/modules/cjs/loader.js:937:14)
at Module.require (internal/modules/cjs/loader.js:1089:19)
at require (internal/modules/cjs/helpers.js:73:18)
at hasCustomGetInitialProps (/Users/.../next/dist/build/utils.js:24:1064)
at build (/Users/...node_modules/next/dist/build/index.js:15:2605)
Loaded env from /Users/.../.env
info - Creating an optimized production build...
info - Using external babel configuration from /Users/.../babel.config.js
info - Collecting page data...
Expected behavior
I would like for it to read my .env file. But if that's not possible, don't crash on me.
Steps to reproduce
Just have a .env in your folder and run serverless
Versions
- OS/Environment: OSX
- @sls-next/serverless-component version: 1.19.0-alpha.21
- Next.js version: Next.js v9.5.5
I have the same error, does anyone know how to solve it?
Since the error is because of an environment file in the same folder you run (serverless delpoy), as a workaround, I found another way of setting my environment variables. Be creative in your setup and find your own.
so one year and still nothing, strong community
Sorry it was missed, unfortunately I'm the only active maintainer right now (always looking for more!) and maintaining in my free time so I might miss some issues.
I could not repro the issue myself from steps above. @pbassut Do you have a minimal repro repo you can share? from the original stacktrace I couldn't see it erroring out in any code in this component (failure seems to originate from next/dist/build/index.js
?)
This issue saved me A LOT of time.
Thanks @pbassut . I finally created a script to rename and recreate .env file on every deploy