I use esbuild-wasm to transpile and bundle React code directly in the browser. Everything works except I get these warning:

warning: Define "process.env.NODE_ENV" when bundling for the browser 13 │ if (process.env.NODE_ENV === 'production')

When I try to use define feature of esbuild-wasm to prevent this warning like this:

const [input, setInput] = useState('');
  const [code, setCode] = useState('');

  const ref = useRef<esbuild.Service>();

  const startService = async () => {
    ref.current = await esbuild.startService({
      worker: true,
      wasmURL: '/esbuild.wasm',
    });
  };

  useEffect(() => {
    startService();
  }, []);

  const handleSubmit = async () => {
    if (!ref.current) return;
    const result = await ref.current.build({
      entryPoints: ['index.js'],
      bundle: true,
      write: false,
      plugins: [unpkgPathPlugin(input)],
      define: {
        global: 'window',
        'process.env.NODE_ENV': '"production"',
      },
    });

    console.log(result);
    setCode(result.outputFiles[0].text);
  };

It shows me Uncaught SyntaxError: Unexpected identifier 'development' and replace the 'process.env.NODE_ENV': '"production"' with ""development"": '"production"'.

0

There are 0 answers