Skip to content

Commit 1ab96d7

Browse files
authored
Merge pull request #745 from motdotla/browser-defaults
Remove browser key except for `fs`
2 parents 3f40e12 + 080779a commit 1ab96d7

3 files changed

Lines changed: 47 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. See [standa
44

55
## [Unreleased](https://github.com/motdotla/dotenv/compare/v16.1.0...master)
66

7+
## [16.1.3](https://github.com/motdotla/dotenv/compare/v16.1.2...v16.1.3) (2023-05-31)
8+
9+
### Removed
10+
11+
- Removed `browser` keys for `path`, `os`, and `crypto` in package.json. These were set to false incorrectly as of 16.1. Instead, if using dotenv on the front-end make sure to include polyfills for `path`, `os`, and `crypto`. [node-polyfill-webpack-plugin](https://github.com/Richienb/node-polyfill-webpack-plugin) provides these.
12+
713
## [16.1.2](https://github.com/motdotla/dotenv/compare/v16.1.1...v16.1.2) (2023-05-31)
814

915
### Changed

README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,44 @@ There are two alternatives to this approach:
525525
1. Preload dotenv: `node --require dotenv/config index.js` (_Note: you do not need to `import` dotenv with this approach_)
526526
2. Create a separate file that will execute `config` first as outlined in [this comment on #133](https://github.com/motdotla/dotenv/issues/133#issuecomment-255298822)
527527

528+
### Why am I getting the error `Module not found: Error: Can't resolve 'crypto|os|path'`?
529+
530+
You are using dotenv on the front-end and have not included a polyfill. Webpack < 5 used to include these for you. Do the following:
531+
532+
```bash
533+
npm install node-polyfill-webpack-plugin
534+
```
535+
536+
Configure your `webpack.config.js` to something like the following.
537+
538+
```js
539+
require('dotenv').config()
540+
541+
const path = require('path');
542+
const webpack = require('webpack')
543+
544+
const NodePolyfillPlugin = require('node-polyfill-webpack-plugin')
545+
546+
module.exports = {
547+
mode: 'development',
548+
entry: './src/index.ts',
549+
output: {
550+
filename: 'bundle.js',
551+
path: path.resolve(__dirname, 'dist'),
552+
},
553+
plugins: [
554+
new NodePolyfillPlugin(),
555+
new webpack.DefinePlugin({
556+
'process.env': {
557+
HELLO: JSON.stringify(process.env.HELLO)
558+
}
559+
}),
560+
]
561+
};
562+
```
563+
564+
Alternatively, just use [dotenv-webpack](https://github.com/mrsteele/dotenv-webpack) which does this and more behind the scenes for you.
565+
528566
### What about variable expansion?
529567

530568
Try [dotenv-expand](https://github.com/motdotla/dotenv-expand)

package.json

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,10 @@
5555
"tar": "^6.1.11",
5656
"typescript": "^4.8.4"
5757
},
58-
"browser": {
59-
"fs": false,
60-
"path": false,
61-
"os": false,
62-
"crypto": false
63-
},
6458
"engines": {
6559
"node": ">=12"
60+
},
61+
"browser": {
62+
"fs": false
6663
}
6764
}

0 commit comments

Comments
 (0)