-
-
Notifications
You must be signed in to change notification settings - Fork 862
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
Getting error while reinstalling the dotenv (updating to 16.4.4
should fix. apologies for the bad patch release of 16.4.3
everyone)
#810
Comments
Hi, getting the same error with latest 16.4.3 version. I am using Node.js version 12.16.3. It looks like the optional chaining operator (?.) is not supported in Node.js v12. Only starting from node v14 it is supported. Your package.json does say this: |
I am using node version 20 |
Found this issue with a similar problem... Looks like the node dependency used might be a major cause. |
I successfully resolved the error by removing the caret (^) from the dotenv version specifier in the package.json file. It appears that there were compatibility issues with the latest version being installed by the caret, so I switched to version 16.0.0, which is functioning as expected. |
Just as a data point, v16.4.3 caused a breakage for us as well. Will update with more findings as we discover them. |
This was a major breaking change. Dependabot auto updated our project and this resulted in a hard crash on our client-side. We weren't expected that from a patch release. |
this was a mistake with our patch release. so sorry, everyone. we are putting out a patch shortly. it appears isolated to node 12. |
until we get the patch out you have 2 options:
|
Sir i am already on node v20.10.0 but still facing the error |
effort happening here: #812 |
Reiterating @utkarsh621x, we are on node v 20.10.0 when we got the error. |
released please upgrade to @utkarsh621x let me know if that fixes it for you as well. that operator is supported for node 20 so i'm surprised you are receiving the error. |
It was failing on attempting to run existsSync on the client-side. (side note: this is in a Next.js app) @ryanolson-aumni what version did you upgrade from with dependabot? was it from |
16.4.4
should fix. apologies for the bad patch release of 16.4.3
everyone)
The issue has been resolved by updating to version 16.4.4. I appreciate the prompt resolution. |
great! |
@motdotla It was from 16.4.2 -> 16.4.3. |
I updated to 16.4.4 and tested locally. I'm still seeing an issue (with the same error message "Unhandled Runtime Error It's failing on fs.existsSync in this block of code: let optionPathsThatExist = []
if (options && options.path) {
if (!Array.isArray(options.path)) {
if (fs.existsSync(options.path)) { |
@ryanolson-aumni are you using webpack? or is this back-end node code? |
Using Next.js 14.1.0 with SWC (speedy web compiler). Then in our _app.jsx (for all pages), we've had: import dotenv from 'dotenv';
dotenv.config({ path: '.env' });
const App = () => {
// not showing implementation
}
export default App; |
the same error message "Unhandled Runtime Error TypeError: fs.existsSync is not a function"
or
Node : 20.11.0 |
@ryanolson-aumni next.js has built-in support for .env files that uses dotenv under the hood: https://nextjs.org/docs/pages/building-your-application/configuring/environment-variables importing dotenv in front-end code will not work because front-end can not read from a file. any use of dotenv for front-end code should be in the build step - not in actual front-end code. or going forward we recommend using
|
@magikcypress looks like you are experiencing the same issue - attempting to use dotenv inside runtime front-end code. front-end does not have a filesystem available to it. you can use https://github.com/mrsteele/dotenv-webpack. |
@motdotla I don't entirely disagree with you. However, we've been using it this way for over a year now (in production) without any issues until 16.4.3. The _app.jsx page runs on the server-side for server-side rendering. Then once pushed to the frontend, can run things client side. Something that changed in 16.4.2->16.4.3 broke this. So I'd still like this to be resolved. |
here's everything that changed since then: v16.4.2...v16.4.4 i'll try and take a look soon and see why this would result in a front-end fs issue when prior it somehow got away with it. |
at a quick glance, it looks like prior there was no for front-end that would result in dotenv.config() silently not working. https://github.com/motdotla/dotenv/blob/master/lib/main.js#L247 @ryanolson-aumni if you remove your historic code
does the app continue to function correctly? I anticipate it might because next.js is taking care of things. |
@ryanolson-aumni update to |
Thanks @motdotla. We'll test out removing the import and |
Just got an error after running npm i and then npm start on my project. Strange thing is that this error started apearing after only when i deleted my package-lock.json and node modules folder then reinstalling them via npm i
`
D:\projects\Winkget proj\Partner\server\node_modules\dotenv\lib\main.js:210
if (options?.encoding) {
^
SyntaxError: Invalid or unexpected token
at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
Node.js v20.10.0
[nodemon] app crashed - waiting for file changes before starting...
`
the file where the error os occuring is located in node modules folder & error is =>
i have checked the same file from my old projects there is some changes that appeared after reinstalling the node modules
this is the old file ==>
this is my main js file where i have import dotenv package =>
The text was updated successfully, but these errors were encountered: