dotenv-module: fs dependency not found
I’ve follow the instructions to add the dotenv module.
When I run npm run dev I’m getting the following error:
This dependency was not found:
- fs in ./node_modules/@nuxtjs/dotenv/dist/index.js
To install it, you can run: npm install --save fs
Digging into this npm package its seems to be a security-holder package. How to solve the error?
<div align="right">This question is available on Nuxt.js community (#c11)</div>About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 19
- Comments: 28 (3 by maintainers)
Commits related to this issue
- Use dotenv in environment Plugin (#6) - Add `dotenv` package & remove `@nuxtjs/dotenv` package - Del `@nuxtjs/dotenv` module from `nuxt.config.ts` - Add webpack config to `nuxt.config.ts` (see nuxt... — committed to nogic1008/nuxt-ts-template by nogic1008 4 years ago
- 開発環境にて dotenv のエラーで動かない問題を修正 - Expected access token - `~/plugins/contentful.js` にて、`require('dotenv').config()` を追加したら改善 - This dependency was not found:* fs in ./node_modules/dotenv/lib/main.js ... — committed to tigrig-study/nuxt-contentful-test by tigrig29 4 years ago
@s-ferdie @tobiasfrei
You could try updating node.
I had that issue a while ago. Not in a nuxt project, but in a classic webpack app. I found that trick somewhere on github that worked for me.
So try adding a
config.nodeobject inside thebuild.extendfunction of yournuxt.config.js:After that if you get the same error, but for other dependencies, like
netortls. You can add them as well in the same config.nodeThe snippet above is not syntactically correct. To save someone some time, here it is (of course the
...are also not syntactically correct, they’re just there to guide you where you place this):Just having a similar issue, and solve it by adding config.node = { fs: “empty”} into the build section in nuxt.config.js. Thanks ~ @nicroto, @abernh
Seeing this same error with latest Node LTS + Nuxt 2.20 and the above mentioned config change does not fix it.
I had to restart the server after changing the config and it works for me. But, i have a problem calling “fs” functions on one node_modules. “fs.writeFileSync is not a function”
via https://github.com/webpack-contrib/css-loader/issues/447 this seems not to be a nuxt issue but a webpack issue and it is “solved” by adding the “node:fs:empty” solution to the webpack config parameters.
This also means @J0ssue that this issue is solved for gridsome by adding the following to the
gridsome.config.js@phikhi thank you so much for helping on this! ❤️
Also this happens if you just try and use
dotenvinnuxt.config.js, like:Which is also solved with the “fs empty” fix.
Is this a safe patch? What if some nuxt modules need fs? Is it better to guard this with:
Or something similar?
I have the same problem, and fixed it by KentChun33333’s resolution.
The solution by @nicroto above solved it for me.
I solved this because i added
dotenvto the devDependencies instead of to the dependencies.