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" errors #2723

Closed
KieranP opened this issue Mar 27, 2021 · 3 comments
Closed

"process is not defined" errors #2723

KieranP opened this issue Mar 27, 2021 · 3 comments

Comments

@KieranP
Copy link

KieranP commented Mar 27, 2021

Describe the bug

I have switched from Snowpack to Vite. After doing so, "vite build" works fine, but when I load the app in the browser, I see "process is not defined" errors.

These seem to be caused by calls to "process.platform" and "process.version" being made in some node_modules. Specifically, in the fs.realpath and glob packages used by graphql-ruby-client frontend JS lib.

I'm not sure if I'm doing something wrong, or Vite is missing something, or if graphql-ruby-client is at fault.

Reproduction

System Info

npx: installed 1 in 1.179s

  System:
    OS: macOS 11.2.3
    CPU: (12) x64 Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
    Memory: 2.20 GB / 32.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 12.14.0 - ~/.nvm/versions/node/v12.14.0/bin/node
    Yarn: 1.22.4 - ~/.nvm/versions/node/v12.14.0/bin/yarn
    npm: 6.13.4 - ~/.nvm/versions/node/v12.14.0/bin/npm
  Browsers:
    Brave Browser: 89.1.22.70
    Chrome: 87.0.4280.88
    Edge: 89.0.774.63
    Firefox: 86.0.1
    Safari: 14.0.3
  npmPackages:
    vite: ^2.1.3 => 2.1.3

Used package manager: yarn

@KieranP
Copy link
Author

KieranP commented Mar 27, 2021

I can get around the issue by putting the following in vite.config.js, but this seems like a hack around, rather than a fix:

define: {
   'process.platform': null,
   'process.version': null,
},

@wheatjs
Copy link

wheatjs commented Mar 27, 2021

I believe this is a problem caused by graphql-ruby-client using node built-ins. This is something that is not supported by Vite and will have to be fixed by the library maintainers.

@patak-dev
Copy link
Member

Closing this now as Vite will not shim node built-ins, in the same way as Webpack 5 has stopped this practice also. The ecosystem will promptly be patched to avoid usage of node builtins.
In the meantime, you can add your own shims for node built-ins. define is one way to work around this. For reference, the snowpack team is working on a rollup plugin that may be a good solution in the future for these cases
https://github.com/snowpackjs/rollup-plugin-polyfill-node

At some point, that project may be adopted by the rollup org.
Note: I had issues running it at this point, I think because of config problems.

@github-actions github-actions bot locked and limited conversation to collaborators Jul 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants