Skip to content

Broken production with Metro bundler (ReferenceError) #736

Description

@zoontek

Hi 👋

On the latest version, a modification (somewhere around here) broke the metro bundler in production mode (and possibly other production apps? It's not tied to minification, but I didn't tried on other bundlers).

urql version: 1.9.7

Steps to reproduce

  1. Create a new React Native project
  2. Add urql@1.9.7, wrap your app in a Provider with an urql client
  3. Build your app for production
  4. Starts your app. It will crash at client init.

Expected behavior

No JS ReferenceError.

Actual behavior

For some reason, the variable is not declared.

Debugging

In order to spot the issue, I created a server to serve the unminified production bundle to my debug application. Create a file at project root:

// server.js

const express = require("express");
const app = express();

app.use((req, res, next) => {
  console.log(req.url);
  res.setHeader("Content-Type", "application/javascript");
  next();
});

app.use("/", express.static("."));
app.use("/assets", express.static("."));
app.get("/status", (_req, res) => {
  res.send("packager-status:running");
});

app.listen(8081, () => {
  console.log("Serving directory as localhost:8081");
});

Build a bundle with:

yarn react-native bundle --entry-file index.js --bundle-output index.bundle --platform ios --dev false --minify false

Then run the server.js file to fake metro bundler, it will be easier to debug.

Fix

The missing declaration is f:

Screenshot 2020-04-22 at 13 57 36

If I add it manually to the bundle, it works:

Screenshot 2020-04-22 at 13 57 58

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug 🐛Oh no! A bug or unintented behaviour.

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions