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

Bug: No matching export in "vite-plugin-node-polyfills/shims/process/dist/index.js" for import "env" #115

Open
ndelangen opened this issue Dec 18, 2024 · 1 comment

Comments

@ndelangen
Copy link

Summary

I'm facing this error:

✘ [ERROR] No matching export in "node_modules/vite-plugin-node-polyfills/shims/process/dist/index.js" for import "env"

    node_modules/.pnpm/[email protected]/node_modules/is-in-ci/index.js:1:8:
      1 │ import {env} from 'node:process';
        ╵         ~~~

✘ [ERROR] No matching export in "node_modules/vite-plugin-node-polyfills/shims/process/dist/index.js" for import "cwd"

    node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected]/node_modules/ink/build/components/ErrorOverview.js:2:9:
      2 │ import { cwd } from 'node:process';

I can fix this by adding:

export const cwd = process.cwd;
@ndelangen
Copy link
Author

For now, I've solved this by setting this in my vite config:

    config.plugins.push(
      nodePolyfills({
        globals: {
          process: false,
        },
        overrides: {
          process: require.resolve('../mocks/node-process.ts'),
          module: require.resolve('../mocks/node-module.ts'),
          util: require.resolve('../mocks/node-util.ts'),
          stream: require.resolve('stream-browserify'),
          buffer: require.resolve('buffer/'),
          assert: require.resolve('assert/'),
          os: require.resolve('os-browserify/browser'),
          tty: require.resolve('tty-browserify'),
        },
      }),
      topLevelAwait()
    );

And this is my mock:

export * from 'vite-plugin-node-polyfills/shims/process';

import process from 'vite-plugin-node-polyfills/shims/process';
export default process;

export const cwd = () => '/';
export const env = {};

I had to disable globals.process in order for it to accept the overrides.process.

FYI, I'm doing something rather niche/experimental, so don't worry if this doesn't get fixed.

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