web icon indicating copy to clipboard operation
web copied to clipboard

[dev-server] React + Typescript: Uncaught ReferenceError: process is not defined

Open theisgroenbech opened this issue 4 years ago • 1 comments

I have tried to use the example in example-projects with React Router.

I have cloned the example, installed react-router-dom and used it in App.tsx.

When running the server and navigating to /demo/ it fails with: Uncaught ReferenceError: process is not defined

I have created a repository with the problem: https://github.com/theisgroenbech/web-dev-server-example/

image

Any ideas?

theisgroenbech avatar Jan 26 '22 09:01 theisgroenbech

Put this before loading any javascript into your html file:

    <script>
      globalThis.process = { env: { NODE_ENV: 'development' } };
    </script>

When bundling with rollup use @rollup/plugin-replace in order to remove development from your modules

romanzy313 avatar Jun 13 '22 23:06 romanzy313

See https://github.com/modernweb-dev/web/issues/1954#issuecomment-1285280464 for a working config using @rollup/plugin-replace to provide process.env.NODE_ENV. Closing as this is not a bug. We could consider updating example projects accordingly, though.

web-padawan avatar Oct 20 '22 10:10 web-padawan