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.

Variable only used in React component name is minified away.

See original GitHub issue

When a variable is only used in React components it can’t find them and minify’s them away causing the code to break.

This issue is also in Eslint reporting 'components' is defined but never used at line 4 col 7 with the ‘no-unused-vars’ rule enabled.

Input:

'use strict';

function test() {
  var components = window.foo.bar;
  return <components.baz/>;
};

test();

Output:

'use strict';function test(){return window.foo.bar,React.createElement(components.baz,null)};test();

Related ESLint issue: https://github.com/eslint/eslint/issues/7418

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
kangaxcommented, Dec 13, 2016

@boopathi that sounds counter-intuitive, let’s just change it?

1reaction
kangaxcommented, Dec 12, 2016

Actually, upon closer examination I see that it works correctly on master with passPerPreset.

require('babel-core').transform('!function(){ var bar = window.foo.bar; return <bar.baz /> }()', {
  passPerPreset: true, 
  presets: ['react', 'babili']
}).code;

"!function () {\n  var a = window.foo.bar;return React.createElement(a.baz, null);\n}();"
Read more comments on GitHub >

github_iconTop Results From Across the Web

React / JSX Dynamic Component Name - Stack Overflow
Keep in mind that your variable should hold the component itself and not just the name of the component as a string. –...
Read more >
JSX In Depth - React
Capitalized types indicate that the JSX tag is referring to a React component. These tags get compiled into a direct reference to the...
Read more >
How to Bundle JavaScript With Rollup — Step-by-Step Tutorial
Learn how to use Rollup as a smaller, more efficient alternative to webpack and Browserify to bundle JavaScript files in this step-by-step tutorial...
Read more >
How To Set Up a React Project with Create React App
Starting a new React project used to be a complicated multi-step process that involved setting up a build system, a code transpiler to...
Read more >
Advanced Features: Next.js Compiler
v12.1.0, Added support for Styled Components, Jest, Relay, Remove React ... SWC can be used for compilation, minification, bundling, and more – and...
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