-
-
Notifications
You must be signed in to change notification settings - Fork 28
Open
Description
I got error stated in title due to the different between how Webpack & Vite load env vars.
I managed to solve the problem by updating Vite's config:
import { defineConfig, loadEnv } from 'vite';
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), '');
return {
define: {
// those two env vars are used by this lib
// ref: https://github.com/thlorenz/parse-link-header/blob/f380d3f99de4a5411b2d7f8da6069bb7529cbf4a/index.js#L7
'process.env.PARSE_LINK_HEADER_MAXLEN': JSON.stringify(env.PARSE_LINK_HEADER_MAXLEN),
'process.env.PARSE_LINK_HEADER_THROW_ON_MAXLEN_EXCEEDED': JSON.stringify(
env.PARSE_LINK_HEADER_THROW_ON_MAXLEN_EXCEEDED,
),
},
// ...
}Refs:
- https://dev.to/whchi/how-to-use-processenv-in-vite-ho9
- A Rollup plupin which does the similar thing: https://www.npmjs.com/package/rollup-plugin-inject-process-env
Related issue #26
#28 also addressed this issue & are resolved in another forked repo, see https://github.com/web3-storage/parse-link-header/blob/490a43ab57f2cb890c924a3705b36da14783f797/README.md?plain=1#L53
There might be more env vas used in the future, & it's not great to maintain this inside our code. Should there be a note for Vite's users in documentation?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels