Skip to content
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

process is not defined error with Vite/Rollup #31

Open
lvnam96 opened this issue May 7, 2023 · 0 comments
Open

process is not defined error with Vite/Rollup #31

lvnam96 opened this issue May 7, 2023 · 0 comments

Comments

@lvnam96
Copy link

lvnam96 commented May 7, 2023

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:

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant