【发布时间】:2022-08-19 02:26:55
【问题描述】:
我创建了一个新的 react 项目,然后添加了 dotenv。
require(\'dotenv\').config();
但我得到了这个:
{{{
ERROR in ./node_modules/dotenv/lib/main.js 1:11-24
Module not found: Error: Can\'t resolve \'fs\' in \'C:\\...\\project\\node_modules\\dotenv\\lib\'
ERROR in ./node_modules/dotenv/lib/main.js 3:13-28
Module not found: Error: Can\'t resolve \'path\' in \'C:\\...\\project\\node_modules\\dotenv\\lib\'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback \'resolve.fallback: { \"path\": require.resolve(\"path-browserify\") }\'
- install \'path-browserify\'
If you don\'t want to include a polyfill, you can use an empty module like this:
resolve.fallback: { \"path\": false }
ERROR in ./node_modules/dotenv/lib/main.js 5:11-24
Module not found: Error: Can\'t resolve \'os\' in \'C:\\...\\project\\node_modules\\dotenv\\lib\'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback \'resolve.fallback: { \"os\": require.resolve(\"os-browserify/browser\") }\'
- install \'os-browserify\'
If you don\'t want to include a polyfill, you can use an empty module like this:
resolve.fallback: { \"os\": false }
}}}
有人可以帮忙吗?
-
我遇到了同样的错误,但无法解决。如果你得到它,请告诉我。
-
这里同样的错误。看着这个话题。
-
你试试 install install
dotenvnpm module link -
我安装了 dotenv