question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

10.0.0-alpha.0: preact/debug doesn't automatically get removed in production

See original GitHub issue

In Preact 8, the whole preact/debug was wrapped in a process.env.NODE_ENV conditional, so it got stripped out of production bundles by default: https://github.com/developit/preact/blob/8/debug/index.js#L3

But in Preact X, when using the .mjs bundle, it will always include the import{checkPropTypes as n}from"prop-types"; line, which in turn will always import the prop-types package. This can be seen in the preact/debug/dist/debug.mjs file. For example here on unpkg: https://unpkg.com/preact@10.0.0-alpha.0/debug/dist/debug.mjs

So now I wrapped preact/debug in my app myself:

if (process.env.NODE_ENV === 'development') {
  require('preact/debug')
}

which is okay, I guess, but the previous behaviour was definitely nicer, and by upgrading to Preact X users could potentially start shipping the debug package to production.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
developitcommented, Mar 7, 2019

We may want to consider only shipping CommonJS and UMD versions of debug for this reason, and using inline requires:

if (process.env.NODE_ENV==='development') {
  require('./debug').initDebug();
  require('./devtools').initDevTools();
}
0reactions
JoviDeCroockcommented, Oct 24, 2020

This is documented here and is a side-effect of how ESM works, we can’t really conditionally import in our bundle (async imports on your side however are an option but not in libraries).

Read more comments on GitHub >

github_iconTop Results From Across the Web

preact/debug doesn't automatically get removed in production ...
In Preact 8, the whole preact/debug was wrapped in a process.env.NODE_ENV conditional, so it got stripped out of production bundles by ...
Read more >
Debugging Preact Apps
Preact ships with a lot of tools to make debugging easier. They're packaged in a single import and can be included by importing...
Read more >
Preact NPM - npm.io
Install the React Developer Tools extension · Import the "preact/debug" module in your app · Set process.env.NODE_ENV to 'development' · Reload and go...
Read more >
Preact - Releases
The past weeks saw a good chunk of bug fixes and a bit of house keeping. Upgrades should be as straightforward as swapping...
Read more >
enzyme-adapter-preact-pure | Yarn - Package Manager
This is an adapter to support using the Enzyme UI component testing library with Preact. For documentation, please see the testing guide on...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found